Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import main
|
3 |
+
import json
|
4 |
+
|
5 |
+
def video_identity(video):
|
6 |
+
video_path = video.name
|
7 |
+
frames = main.extract_frames(video_path)
|
8 |
+
pepsi_pts, cocacola_pts = main.detect_logos(frames)
|
9 |
+
def to_serializable(obj):
|
10 |
+
if isinstance(obj, (list, dict)):
|
11 |
+
return obj
|
12 |
+
elif hasattr(obj, 'tolist'):
|
13 |
+
return obj.tolist() # Convert numpy arrays or tensors
|
14 |
+
elif hasattr(obj, 'item'):
|
15 |
+
return obj.item() # Convert single element tensors
|
16 |
+
else:
|
17 |
+
return str(obj) # Convert other non-serializable objects to string
|
18 |
+
|
19 |
+
output = {
|
20 |
+
"Pepsi_pts": [entry["timestamp"] for entry in pepsi_pts],
|
21 |
+
"CocaCola_pts": [entry["timestamp"] for entry in cocacola_pts],
|
22 |
+
"Pepsi_details": [ {k: to_serializable(v) for k, v in entry.items()} for entry in pepsi_pts ],
|
23 |
+
"CocaCola_details": [ {k: to_serializable(v) for k, v in entry.items()} for entry in cocacola_pts ]
|
24 |
+
}
|
25 |
+
return json.dumps(output)
|
26 |
+
|
27 |
+
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=video_identity,
|
30 |
+
inputs=[
|
31 |
+
"file",
|
32 |
+
],
|
33 |
+
outputs="json"
|
34 |
+
)
|
35 |
+
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|