Spaces:
Runtime error
Runtime error
Commit
·
1f8282c
1
Parent(s):
0da2b4b
Update app.py
Browse files
app.py
CHANGED
@@ -112,23 +112,75 @@ def predict(youtube_url_or_file_path):
|
|
112 |
return label_to_score, gif_path
|
113 |
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
|
|
134 |
app.launch()
|
|
|
112 |
return label_to_score, gif_path
|
113 |
|
114 |
|
115 |
+
# Create the Gradio app
|
116 |
+
app = gr.Blocks()
|
117 |
+
|
118 |
+
with app:
|
119 |
+
# Title and description
|
120 |
+
gr.Markdown("# **<p align='center'>Video Classification with 🤗 Transformers</p>**")
|
121 |
+
gr.Markdown(
|
122 |
+
"""
|
123 |
+
<p style='text-align: center'>
|
124 |
+
Perform video classification with <a href='https://huggingface.co/models?pipeline_tag=video-classification&library=transformers' target='_blank'>HuggingFace Transformers video models</a>.
|
125 |
+
<br> For zero-shot classification, you can use the <a href='https://huggingface.co/spaces/fcakyon/zero-shot-video-classification' target='_blank'>zero-shot classification demo</a>.
|
126 |
+
</p>
|
127 |
+
"""
|
128 |
+
)
|
129 |
+
|
130 |
+
with gr.Row():
|
131 |
+
# Left Column: Model Selection and Input
|
132 |
+
with gr.Column():
|
133 |
+
model_names_dropdown = gr.Dropdown(
|
134 |
+
choices=VALID_VIDEOCLASSIFICATION_MODELS,
|
135 |
+
label="Model:",
|
136 |
+
show_label=True,
|
137 |
+
value=DEFAULT_MODEL,
|
138 |
+
)
|
139 |
+
model_names_dropdown.change(fn=select_model, inputs=model_names_dropdown)
|
140 |
+
|
141 |
+
with gr.TabGroup() as tabs:
|
142 |
+
# Youtube URL Tab
|
143 |
+
with gr.Tab(label="Youtube URL"):
|
144 |
+
gr.Markdown("### **Provide a Youtube video URL**")
|
145 |
+
youtube_url = gr.Textbox(label="Youtube URL:", show_label=True)
|
146 |
+
youtube_url_predict_btn = gr.Button(value="Predict")
|
147 |
+
|
148 |
+
# Local File Tab
|
149 |
+
with gr.Tab(label="Local File"):
|
150 |
+
gr.Markdown("### **Upload a video file**")
|
151 |
+
video_file = gr.Video(label="Video File:", show_label=True)
|
152 |
+
local_video_predict_btn = gr.Button(value="Predict")
|
153 |
+
|
154 |
+
# Middle Column: Display Input Clip
|
155 |
+
with gr.Column():
|
156 |
+
video_gif = gr.Image(
|
157 |
+
label="Input Clip",
|
158 |
+
show_label=True,
|
159 |
+
)
|
160 |
+
|
161 |
+
# Right Column: Display Predictions
|
162 |
+
with gr.Column():
|
163 |
+
predictions = gr.Label(
|
164 |
+
label="Predictions:", show_label=True, num_top_classes=5
|
165 |
+
)
|
166 |
+
|
167 |
+
# Examples and Prediction Buttons
|
168 |
+
gr.Markdown("**Examples:**")
|
169 |
+
gr.Examples(
|
170 |
+
examples,
|
171 |
+
youtube_url,
|
172 |
+
[predictions, video_gif],
|
173 |
+
fn=predict,
|
174 |
+
cache_examples=True,
|
175 |
+
)
|
176 |
+
|
177 |
+
# Click handlers for prediction buttons
|
178 |
+
youtube_url_predict_btn.click(
|
179 |
+
predict, inputs=youtube_url, outputs=[predictions, video_gif]
|
180 |
+
)
|
181 |
+
local_video_predict_btn.click(
|
182 |
+
predict, inputs=video_file, outputs=[predictions, video_gif]
|
183 |
+
)
|
184 |
|
185 |
+
# Launch the Gradio app
|
186 |
app.launch()
|