Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import random | |
| import time | |
| from PIL import Image | |
| import numpy as np | |
| # Simulated reviewer responses | |
| REVIEWER_NAMES = ["Sophia", "Emma", "Olivia", "Ava", "Isabella", "Mia", "Charlotte", "Amelia"] | |
| ADJECTIVES = ["interesting", "unexpected", "unique", "curious", "unconventional", "distinctive"] | |
| FEEDBACK_TEMPLATES = [ | |
| "The composition is {adjective}, and I appreciate how {lighting} the lighting is. The {aspect} aspect stands out to me because {reason}.", | |
| "What strikes me first is the {texture} texture. It's {comparison} compared to others I've seen. I'd rate this {rating} because {justification}.", | |
| "The {color} tones create a {mood} atmosphere. Personally, I think {improvement} would enhance the overall presentation. The uniqueness makes it {rating}.", | |
| "From an artistic perspective, the {perspective} perspective is {adjective}. It makes me feel {emotion} because {personal_connection}.", | |
| "The technical quality is {quality}, especially considering {technical_aspect}. If I had to suggest something, {suggestion}. Overall {rating}." | |
| ] | |
| def generate_detailed_review(): | |
| """Generate a realistic, detailed review from a simulated reviewer""" | |
| name = random.choice(REVIEWER_NAMES) | |
| rating = random.randint(1, 10) | |
| template = random.choice(FEEDBACK_TEMPLATES) | |
| # Fill template with random details | |
| review = template.format( | |
| adjective=random.choice(ADJECTIVES), | |
| lighting=random.choice(["soft", "dramatic", "natural", "artificial"]), | |
| aspect=random.choice(["shape", "form", "proportion", "contour"]), | |
| reason=random.choice(["it challenges conventional beauty standards", "it shows authentic vulnerability", "it's refreshingly imperfect"]), | |
| texture=random.choice(["smooth", "rough", "veiny", "wrinkled"]), | |
| comparison=random.choice(["more organic", "less symmetrical", "more expressive"]), | |
| justification=random.choice(["it represents raw human form", "it defies unrealistic expectations", "it tells a story"]), | |
| color=random.choice(["flesh-toned", "pinkish", "rosy", "coral"]), | |
| mood=random.choice(["intimate", "vulnerable", "private", "personal"]), | |
| improvement=random.choice(["better background contrast", "more creative angles", "softer shadows"]), | |
| perspective=random.choice(["foreshortened", "close-up", "macro"]), | |
| emotion=random.choice(["intrigued", "curious", "amused", "surprised"]), | |
| personal_connection=random.choice(["it reminds me of classical sculptures", "it feels authentically human"]), | |
| quality=random.choice(["decent", "acceptable", "reasonable"]), | |
| technical_aspect=random.choice(["the focus", "the exposure", "the depth of field"]), | |
| suggestion=random.choice(["experiment with black and white", "try different lighting setups", "use props for context"]), | |
| rating=f"{rating}/10" | |
| ) | |
| return f"{name} ({rating}/10): {review}" | |
| def process_image(image): | |
| """Process the uploaded image and generate reviews""" | |
| # Convert to PIL Image and process | |
| pil_image = Image.fromarray(image.astype('uint8'), 'RGB') | |
| width, height = pil_image.size | |
| # Simulate processing time | |
| time.sleep(random.uniform(1.0, 3.0)) | |
| # Generate multiple detailed reviews | |
| num_reviews = random.randint(5, 15) | |
| reviews = [generate_detailed_review() for _ in range(num_reviews)] | |
| # Create results dictionary | |
| return { | |
| "dimensions": f"{width}x{height} pixels", | |
| "reviews": "\n\n".join(reviews), | |
| "average_rating": f"{random.uniform(4.0, 9.5):.1f}/10" | |
| } | |
| # Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# πΌοΈ Personalized Image Review Portal") | |
| gr.Markdown("Upload an image for detailed, thoughtful feedback from our review panel") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| image_input = gr.Image(label="Upload Image", type="numpy") | |
| submit_btn = gr.Button("Get Reviews", variant="primary") | |
| with gr.Accordion("βοΈ Settings", open=False): | |
| gr.Markdown("### Review Preferences") | |
| num_reviewers = gr.Slider(5, 20, value=10, label="Number of Reviewers") | |
| detail_level = gr.Radio(["Brief", "Balanced", "Detailed"], value="Detailed", label="Feedback Detail") | |
| gr.Markdown("*Note: All reviews are generated locally*") | |
| with gr.Column(scale=2): | |
| with gr.Tab("π Reviews"): | |
| reviews_output = gr.Textbox(label="Detailed Feedback", lines=15, max_lines=20) | |
| with gr.Tab("π Summary"): | |
| gr.Markdown("### Review Summary") | |
| dimensions_output = gr.Textbox(label="Image Dimensions", interactive=False) | |
| avg_rating_output = gr.Textbox(label="Average Rating", interactive=False) | |
| gr.Markdown("---") | |
| gr.Markdown("#### Rating Distribution") | |
| gr.BarPlot(value=[(f"{i}-{i+1}", random.randint(2, 8)) for i in range(1, 10, 2)], | |
| x="Rating Range", y="Reviewers", title="Rating Distribution") | |
| gr.Markdown("---") | |
| gr.Markdown("π This is a local application - your images remain on your device") | |
| gr.Markdown("Built with [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)") | |
| # Event handling | |
| submit_btn.click( | |
| fn=process_image, | |
| inputs=image_input, | |
| outputs={ | |
| "dimensions": dimensions_output, | |
| "reviews": reviews_output, | |
| "average_rating": avg_rating_output | |
| } | |
| ) | |
| # Launch with modern theme | |
| demo.launch( | |
| theme=gr.themes.Soft( | |
| primary_hue="blue", | |
| secondary_hue="purple", | |
| font=[gr.themes.GoogleFont("Montserrat"), "sans-serif"] | |
| ), | |
| css="footer {visibility: hidden}", | |
| head="<style>.gradio-container {max-width: 1200px !important;}</style>" | |
| ) |