Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| # Custom CSS for styling | |
| css = """ | |
| .criteria-name { | |
| font-size: 18px; | |
| font-weight: bold; | |
| margin-bottom: 4px; | |
| } | |
| .criteria-description { | |
| font-size: 14px; | |
| color: #555; | |
| margin-bottom: 12px; | |
| } | |
| .subcriteria { | |
| margin-bottom: 20px; | |
| padding: 10px; | |
| border-bottom: 1px solid #eee; | |
| } | |
| .category-header { | |
| margin-top: 30px; | |
| margin-bottom: 10px; | |
| font-size: 20px; | |
| font-weight: bold; | |
| border-bottom: 2px solid #ccc; | |
| padding-bottom: 4px; | |
| } | |
| .app-header { | |
| text-align: center; | |
| margin-bottom: 30px; | |
| } | |
| """ | |
| # Define criteria grouped by category with names and descriptions | |
| criteria = { | |
| "Writing": [ | |
| {"name": "Dialogue", "description": "Word choice, realism, subtext, and implications."}, | |
| {"name": "Screenwriting", "description": "Structure, plot progression, and narrative choices."}, | |
| {"name": "Character Development", "description": "Depth, relatability, motivations, and arcs."}, | |
| {"name": "Theme & Symbolism", "description": "Use of deeper meaning, metaphors, and thematic consistency."} | |
| ], | |
| "Cinematography": [ | |
| {"name": "Camera Work", "description": "Shot composition, stability, movement, and angles."}, | |
| {"name": "Lighting", "description": "Contrast, exposure control, and mood-setting."}, | |
| {"name": "Color Grading", "description": "Palette consistency, contrast, and emotional tone."}, | |
| {"name": "Framing & Aspect Ratio", "description": "Use of space, focus, and visual storytelling."} | |
| ], | |
| "Editing & Pacing": [ | |
| {"name": "Scene Transitions", "description": "Smoothness, creativity, and effectiveness."}, | |
| {"name": "Continuity", "description": "Logical flow and lack of visual inconsistencies."}, | |
| {"name": "Pacing", "description": "Balance between slow and fast scenes, engagement level."}, | |
| {"name": "Use of Montage", "description": "Storytelling efficiency via edited sequences."} | |
| ], | |
| "Sound": [ | |
| {"name": "Dialogue Mixing", "description": "Clarity, balance, and intelligibility of speech."}, | |
| {"name": "Foley & Sound Effects", "description": "Realism, accuracy, and integration into the world."}, | |
| {"name": "Score & Music", "description": "Uniqueness, memorability, and emotional impact."}, | |
| {"name": "Spatial Audio & Atmosphere", "description": "Immersion, ambient sound accuracy, and use of silence."} | |
| ], | |
| "Directing & Performance": [ | |
| {"name": "Directing", "description": "Cohesion of vision, creative choices, and execution."}, | |
| {"name": "Acting", "description": "Expression, dialogue delivery, and emotional depth."}, | |
| {"name": "Blocking & Staging", "description": "Character positioning, movement, and scene composition."}, | |
| {"name": "Action & Stunt Choreography", "description": "Realism, execution, and visual readability."} | |
| ], | |
| "Production & Visuals": [ | |
| {"name": "Production Design", "description": "Set design, world-building, and authenticity."}, | |
| {"name": "Costume & Makeup", "description": "Period accuracy, character enhancement, and detailing."}, | |
| {"name": "Practical Effects & Props", "description": "Use of real elements over CGI, believability."}, | |
| {"name": "VFX & CGI Integration", "description": "Quality, realism, and seamless blending."} | |
| ], | |
| "Engagement & Replay Value": [ | |
| {"name": "Plot", "description": "Uniqueness, engagement, predictability, and emotional weight."}, | |
| {"name": "Originality", "description": "Avoidance of clichés, fresh storytelling, and innovation."}, | |
| {"name": "Rewatchability", "description": "Whether the movie holds up over multiple viewings."}, | |
| {"name": "Emotional Impact", "description": "Strength of connection, intensity of response."} | |
| ] | |
| } | |
| def calculate_score(*ratings): | |
| # Exclude blank ratings (value 0 means not rated) | |
| valid = [r for r in ratings if r and r > 0] | |
| if not valid: | |
| return "<h2 style='text-align:center;'>Please rate at least one criterion.</h2>" | |
| avg = sum(valid) / len(valid) | |
| scaled_score = (1/18) * (avg ** 2) + (19/18) * avg - (1/9) | |
| return f"<h2 style='text-align:center;'>Final Scaled Score: {scaled_score:.2f} / 10</h2>" | |
| with gr.Blocks(css=css, title="Movie Rating System") as demo: | |
| gr.HTML("<h1 class='app-header'>Movie Rating System</h1>") | |
| rating_components = [] | |
| # Loop over each category and its subcriteria | |
| for group, subcriteria in criteria.items(): | |
| gr.HTML(f"<div class='category-header'>{group}</div>") | |
| for crit in subcriteria: | |
| with gr.Column(elem_classes="subcriteria"): | |
| gr.HTML(f"<div class='criteria-name'>{crit['name']}</div>") | |
| gr.HTML(f"<div class='criteria-description'>{crit['description']}</div>") | |
| # Star rating component (0 means not rated) | |
| rating = gr.Rating(num_stars=7, value=0, label="") | |
| rating_components.append(rating) | |
| calculate_btn = gr.Button("Calculate Score") | |
| output = gr.HTML("", elem_classes="app-header") | |
| calculate_btn.click(fn=calculate_score, inputs=rating_components, outputs=output) | |
| demo.launch() | |