Spaces:
Sleeping
Sleeping
Commit
·
4db543e
1
Parent(s):
d7ac985
Add app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
video_cls = pipeline(model="mohamedsaeed823/VideoMAEF-finetuned-ARSL-diverse-dataset")
|
5 |
+
phrase_map = {
|
6 |
+
'Alhamdulillah': "الحمد لله",
|
7 |
+
'Good bye': "مع السلامة",
|
8 |
+
'Good evening': "مساء الخير",
|
9 |
+
'Good morning': "صباح الخير",
|
10 |
+
'How are you': "ايه الاخبار",
|
11 |
+
'I am pleased to meet you': "فرصة سعيدة",
|
12 |
+
'I am fine': "انا كويس",
|
13 |
+
'I am sorry': "انا اسف",
|
14 |
+
'Not bad': "مش وحش ",
|
15 |
+
'Salam aleikum': "السلام عليكم",
|
16 |
+
'Sorry (Excuse me)': "لو سمحت",
|
17 |
+
'Thanks': "شكرا"
|
18 |
+
}
|
19 |
+
def classify_video(video_path):
|
20 |
+
try:
|
21 |
+
result=video_cls(video_path,top_k=3,frame_sampling_rate=6) # try to sample a frame every 6 seconds for better video understanding if the video is long enough
|
22 |
+
except Exception as e:
|
23 |
+
result=video_cls(video_path,top_k=3,frame_sampling_rate=3) # if the video is not long enough sample every 3 seconds
|
24 |
+
|
25 |
+
# Extract the top 3 label and their scores from the classification results
|
26 |
+
top_label = [phrase_map[result[0]['label']], phrase_map[result[1]['label']], phrase_map[result[2]['label']]]
|
27 |
+
top_label_confidence = [result[0]['score'], result[1]['score'], result[2]['score']]
|
28 |
+
return dict(zip(top_label, top_label_confidence))
|
29 |
+
|
30 |
+
demo = gr.Interface(fn=classify_video, inputs=gr.Video(sources=["upload"]), outputs=gr.Label(num_top_classes=3))
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch()
|