"""Input form components for the movie predictor.""" from __future__ import annotations import gradio as gr def create_input_form(feature_options: dict[str, list[str]]) -> tuple[dict[str, gr.components.Component], list[gr.components.Component]]: """Create the input form with all movie attributes.""" inputs = {} with gr.Row(): with gr.Column(scale=2): gr.Markdown("### 📊 Core Metrics") inputs["budget"] = gr.Number( label="Budget ($)", value=50_000_000, info="Production budget in USD" ) inputs["popularity"] = gr.Number( label="Popularity Score", value=10.0, info="Trending score (0-100)" ) inputs["runtime"] = gr.Number( label="Runtime (minutes)", value=105, info="Movie duration" ) with gr.Column(scale=2): gr.Markdown("### 📅 Release Info") inputs["release_date"] = gr.Textbox( label="Release Date", value="2015-06-12", info="Format: YYYY-MM-DD" ) inputs["original_language"] = gr.Dropdown( label="Original Language", choices=["en", "zh", "ja", "other"], value="en" ) with gr.Column(scale=1): gr.Markdown("### ✓ Flags") inputs["belongs_to_collection"] = gr.Checkbox( label="Part of Collection", value=False ) inputs["homepage"] = gr.Checkbox( label="Has Homepage", value=False ) with gr.Row(): with gr.Column(): gr.Markdown("### 🎬 Movie Details") inputs["title"] = gr.Textbox( label="Title", value="Sample Movie" ) inputs["tagline"] = gr.Textbox( label="Tagline", value="A new story begins" ) inputs["overview"] = gr.Textbox( label="Overview", value="A movie about discovery, conflict, and ambition.", lines=3 ) with gr.Row(): with gr.Column(): gr.Markdown("### 👥 Cast & Crew Statistics") gr.Markdown("*These are typically derived from cast/crew data. Estimate if unknown.*") with gr.Row(): inputs["num_of_cast"] = gr.Number( label="Total Cast Members", value=10, info="Number of actors" ) inputs["num_of_crew"] = gr.Number( label="Total Crew Members", value=10, info="Number of crew" ) with gr.Row(): inputs["gender_cast_1"] = gr.Number( label="Female Cast (Gender=1)", value=4, info="Number of female actors" ) inputs["gender_cast_2"] = gr.Number( label="Male Cast (Gender=2)", value=5, info="Number of male actors" ) inputs["count_cast_other"] = gr.Number( label="Other/Unknown Gender", value=1, info="Other gender identities" ) with gr.Accordion("🎭 Optional: Genres, Companies & More", open=False): with gr.Row(): inputs["genres"] = gr.Dropdown( label="Genres", choices=feature_options.get("genres", []), multiselect=True, info="Select one or more genres" ) inputs["production_companies"] = gr.Dropdown( label="Production Companies", choices=feature_options.get("production_companies", []), multiselect=True, info="Select production companies" ) with gr.Row(): inputs["keywords"] = gr.Dropdown( label="Keywords", choices=feature_options.get("Keywords", []), multiselect=True, info="Content keywords" ) inputs["cast"] = gr.Dropdown( label="Notable Cast", choices=feature_options.get("cast", []), multiselect=True, info="Famous actors" ) # Return both dict and ordered list for compatibility ordered_list = [ inputs["budget"], inputs["popularity"], inputs["runtime"], inputs["release_date"], inputs["original_language"], inputs["belongs_to_collection"], inputs["homepage"], inputs["title"], inputs["tagline"], inputs["overview"], inputs["num_of_cast"], inputs["num_of_crew"], inputs["gender_cast_1"], inputs["gender_cast_2"], inputs["count_cast_other"], inputs["genres"], inputs["production_companies"], inputs["keywords"], inputs["cast"], ] return inputs, ordered_list