Spaces:
Sleeping
Sleeping
File size: 5,388 Bytes
b490ee7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | """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
|