Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +120 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Simulated reviewer responses
|
| 8 |
+
REVIEWER_NAMES = ["Sophia", "Emma", "Olivia", "Ava", "Isabella", "Mia", "Charlotte", "Amelia"]
|
| 9 |
+
ADJECTIVES = ["interesting", "unexpected", "unique", "curious", "unconventional", "distinctive"]
|
| 10 |
+
FEEDBACK_TEMPLATES = [
|
| 11 |
+
"The composition is {adjective}, and I appreciate how {lighting} the lighting is. The {aspect} aspect stands out to me because {reason}.",
|
| 12 |
+
"What strikes me first is the {texture} texture. It's {comparison} compared to others I've seen. I'd rate this {rating} because {justification}.",
|
| 13 |
+
"The {color} tones create a {mood} atmosphere. Personally, I think {improvement} would enhance the overall presentation. The uniqueness makes it {rating}.",
|
| 14 |
+
"From an artistic perspective, the {perspective} perspective is {adjective}. It makes me feel {emotion} because {personal_connection}.",
|
| 15 |
+
"The technical quality is {quality}, especially considering {technical_aspect}. If I had to suggest something, {suggestion}. Overall {rating}."
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
def generate_detailed_review():
|
| 19 |
+
"""Generate a realistic, detailed review from a simulated reviewer"""
|
| 20 |
+
name = random.choice(REVIEWER_NAMES)
|
| 21 |
+
rating = random.randint(1, 10)
|
| 22 |
+
template = random.choice(FEEDBACK_TEMPLATES)
|
| 23 |
+
|
| 24 |
+
# Fill template with random details
|
| 25 |
+
review = template.format(
|
| 26 |
+
adjective=random.choice(ADJECTIVES),
|
| 27 |
+
lighting=random.choice(["soft", "dramatic", "natural", "artificial"]),
|
| 28 |
+
aspect=random.choice(["shape", "form", "proportion", "contour"]),
|
| 29 |
+
reason=random.choice(["it challenges conventional beauty standards", "it shows authentic vulnerability", "it's refreshingly imperfect"]),
|
| 30 |
+
texture=random.choice(["smooth", "rough", "veiny", "wrinkled"]),
|
| 31 |
+
comparison=random.choice(["more organic", "less symmetrical", "more expressive"]),
|
| 32 |
+
justification=random.choice(["it represents raw human form", "it defies unrealistic expectations", "it tells a story"]),
|
| 33 |
+
color=random.choice(["flesh-toned", "pinkish", "rosy", "coral"]),
|
| 34 |
+
mood=random.choice(["intimate", "vulnerable", "private", "personal"]),
|
| 35 |
+
improvement=random.choice(["better background contrast", "more creative angles", "softer shadows"]),
|
| 36 |
+
perspective=random.choice(["foreshortened", "close-up", "macro"]),
|
| 37 |
+
emotion=random.choice(["intrigued", "curious", "amused", "surprised"]),
|
| 38 |
+
personal_connection=random.choice(["it reminds me of classical sculptures", "it feels authentically human"]),
|
| 39 |
+
quality=random.choice(["decent", "acceptable", "reasonable"]),
|
| 40 |
+
technical_aspect=random.choice(["the focus", "the exposure", "the depth of field"]),
|
| 41 |
+
suggestion=random.choice(["experiment with black and white", "try different lighting setups", "use props for context"]),
|
| 42 |
+
rating=f"{rating}/10"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
return f"{name} ({rating}/10): {review}"
|
| 46 |
+
|
| 47 |
+
def process_image(image):
|
| 48 |
+
"""Process the uploaded image and generate reviews"""
|
| 49 |
+
# Convert to PIL Image and process
|
| 50 |
+
pil_image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 51 |
+
width, height = pil_image.size
|
| 52 |
+
|
| 53 |
+
# Simulate processing time
|
| 54 |
+
time.sleep(random.uniform(1.0, 3.0))
|
| 55 |
+
|
| 56 |
+
# Generate multiple detailed reviews
|
| 57 |
+
num_reviews = random.randint(5, 15)
|
| 58 |
+
reviews = [generate_detailed_review() for _ in range(num_reviews)]
|
| 59 |
+
|
| 60 |
+
# Create results dictionary
|
| 61 |
+
return {
|
| 62 |
+
"dimensions": f"{width}x{height} pixels",
|
| 63 |
+
"reviews": "\n\n".join(reviews),
|
| 64 |
+
"average_rating": f"{random.uniform(4.0, 9.5):.1f}/10"
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
# Gradio interface
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("# 🖼️ Personalized Image Review Portal")
|
| 70 |
+
gr.Markdown("Upload an image for detailed, thoughtful feedback from our review panel")
|
| 71 |
+
|
| 72 |
+
with gr.Row():
|
| 73 |
+
with gr.Column(scale=1):
|
| 74 |
+
image_input = gr.Image(label="Upload Image", type="numpy")
|
| 75 |
+
submit_btn = gr.Button("Get Reviews", variant="primary")
|
| 76 |
+
|
| 77 |
+
with gr.Accordion("⚙️ Settings", open=False):
|
| 78 |
+
gr.Markdown("### Review Preferences")
|
| 79 |
+
num_reviewers = gr.Slider(5, 20, value=10, label="Number of Reviewers")
|
| 80 |
+
detail_level = gr.Radio(["Brief", "Balanced", "Detailed"], value="Detailed", label="Feedback Detail")
|
| 81 |
+
gr.Markdown("*Note: All reviews are generated locally*")
|
| 82 |
+
|
| 83 |
+
with gr.Column(scale=2):
|
| 84 |
+
with gr.Tab("📝 Reviews"):
|
| 85 |
+
reviews_output = gr.Textbox(label="Detailed Feedback", lines=15, max_lines=20)
|
| 86 |
+
|
| 87 |
+
with gr.Tab("📊 Summary"):
|
| 88 |
+
gr.Markdown("### Review Summary")
|
| 89 |
+
dimensions_output = gr.Textbox(label="Image Dimensions", interactive=False)
|
| 90 |
+
avg_rating_output = gr.Textbox(label="Average Rating", interactive=False)
|
| 91 |
+
gr.Markdown("---")
|
| 92 |
+
gr.Markdown("#### Rating Distribution")
|
| 93 |
+
gr.BarPlot(value=[(f"{i}-{i+1}", random.randint(2, 8)) for i in range(1, 10, 2)],
|
| 94 |
+
x="Rating Range", y="Reviewers", title="Rating Distribution")
|
| 95 |
+
|
| 96 |
+
gr.Markdown("---")
|
| 97 |
+
gr.Markdown("🔒 This is a local application - your images remain on your device")
|
| 98 |
+
gr.Markdown("Built with [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)")
|
| 99 |
+
|
| 100 |
+
# Event handling
|
| 101 |
+
submit_btn.click(
|
| 102 |
+
fn=process_image,
|
| 103 |
+
inputs=image_input,
|
| 104 |
+
outputs={
|
| 105 |
+
"dimensions": dimensions_output,
|
| 106 |
+
"reviews": reviews_output,
|
| 107 |
+
"average_rating": avg_rating_output
|
| 108 |
+
}
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
# Launch with modern theme
|
| 112 |
+
demo.launch(
|
| 113 |
+
theme=gr.themes.Soft(
|
| 114 |
+
primary_hue="blue",
|
| 115 |
+
secondary_hue="purple",
|
| 116 |
+
font=[gr.themes.GoogleFont("Montserrat"), "sans-serif"]
|
| 117 |
+
),
|
| 118 |
+
css="footer {visibility: hidden}",
|
| 119 |
+
head="<style>.gradio-container {max-width: 1200px !important;}</style>"
|
| 120 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
Pillow
|
| 3 |
+
gradio>=6.0
|
| 4 |
+
requests
|