Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from utils.predict import predict_action
|
3 |
+
import os
|
4 |
+
import glob
|
5 |
+
|
6 |
+
##Create list of examples to be loaded
|
7 |
+
example_list = glob.glob("examples/*")
|
8 |
+
example_list = list(map(lambda el:[el], example_list))
|
9 |
+
|
10 |
+
|
11 |
+
demo = gr.Blocks()
|
12 |
+
|
13 |
+
|
14 |
+
with demo:
|
15 |
+
|
16 |
+
gr.Markdown("# **<p align='center'>Video Classification with Transformers</p>**")
|
17 |
+
gr.Markdown("This space demonstrates the use of hybrid Transformer-based models for video classification that operate on CNN feature maps.")
|
18 |
+
|
19 |
+
with gr.Tabs():
|
20 |
+
|
21 |
+
with gr.TabItem("Upload & Predict"):
|
22 |
+
with gr.Box():
|
23 |
+
|
24 |
+
with gr.Row():
|
25 |
+
input_video = gr.Video(label="Input Video", show_label=True)
|
26 |
+
output_label = gr.Label(label="Model Output", show_label=True)
|
27 |
+
output_gif = gr.Image(label="Video Gif", show_label=True)
|
28 |
+
|
29 |
+
gr.Markdown("**Predict**")
|
30 |
+
|
31 |
+
with gr.Box():
|
32 |
+
with gr.Row():
|
33 |
+
submit_button = gr.Button("Submit")
|
34 |
+
|
35 |
+
gr.Markdown("**Examples:**")
|
36 |
+
gr.Markdown("The model is trained to classify videos belonging to the following classes: CricketShot, PlayingCello, Punch, ShavingBeard, TennisSwing")
|
37 |
+
# gr.Markdown("CricketShot, PlayingCello, Punch, ShavingBeard, TennisSwing")
|
38 |
+
|
39 |
+
with gr.Column():
|
40 |
+
gr.Examples(example_list, [input_video], [output_label,output_gif], predict_action, cache_examples=True)
|
41 |
+
|
42 |
+
submit_button.click(predict_action, inputs=input_video, outputs=[output_label,output_gif])
|
43 |
+
|
44 |
+
gr.Markdown('\n Demo created by: <a href=\"https://www.linkedin.com/in/shivalika-singh/\">Shivalika Singh</a> <br> Based on this <a href=\"https://keras.io/examples/vision/video_transformers/\">Keras example</a> by <a href=\"https://twitter.com/RisingSayak\">Sayak Paul</a> <br> Demo Powered by this <a href=\"https://huggingface.co/shivi/video-transformers/\"> Video Classification</a> model')
|
45 |
+
|
46 |
+
demo.launch()
|