Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import warnings
|
2 |
warnings.filterwarnings("ignore")
|
3 |
import gradio as gr
|
4 |
-
|
|
|
|
|
5 |
import os
|
6 |
|
7 |
# --- Function to construct the final query ---
|
@@ -33,31 +35,36 @@ def process_video_and_questions(video, sitting, hands, location, screen):
|
|
33 |
final_response = f"<video_name>{video_name}</video_name>" + " " + response
|
34 |
return final_response
|
35 |
|
36 |
-
# Video and text inputs for the interface
|
37 |
-
video = gr.Video(label="Video")
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
# Output for the interface
|
46 |
-
response = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
|
47 |
|
48 |
# Examples for the interface
|
49 |
examples = [
|
50 |
-
["videos/2016-01-01_0100_US_KNBC_Channel_4_News_1867.16-1871.38_now.mp4",],
|
51 |
-
["videos/2016-01-01_0200_US_KNBC_Channel_4_News_1329.12-1333.29_tonight.mp4",],
|
52 |
-
["videos/2016-01-01_0830_US_KNBC_Tonight_Show_with_Jimmy_Fallon_725.45-729.76_tonight.mp4",],
|
53 |
-
["videos/2016-01-01_0200_US_KOCE_The_PBS_Newshour_577.03-581.31_tonight.mp4"],
|
54 |
-
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4"],
|
55 |
-
["videos/2016-01-02_0735_US_KCBS_Late_Show_with_Stephen_Colbert_285.94-290.67_this_year.mp4"],
|
56 |
-
["videos/2016-01-13_2200_US_KTTV-FOX_The_Doctor_Oz_Show_1709.79-1714.17_this_month.mp4"],
|
57 |
-
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4"],
|
58 |
-
["videos/2016-01-01_1300_US_KNBC_Today_in_LA_at_5am_12.46-16.95_this_morning.mp4"],
|
59 |
-
["videos/2016-01-05_0200_US_KNBC_Channel_4_News_1561.29-1565.95_next_week.mp4"],
|
60 |
-
["videos/2016-01-28_0700_US_KNBC_Channel_4_News_at_11PM_629.56-633.99_in_the_future.mp4"]
|
61 |
]
|
62 |
|
63 |
# Title, description, and article for the interface
|
@@ -69,16 +76,39 @@ custom_theme = gr.themes.Soft(
|
|
69 |
primary_hue="red",
|
70 |
secondary_hue="red")
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
)
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import warnings
|
2 |
warnings.filterwarnings("ignore")
|
3 |
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
from src.video_model import describe_video
|
6 |
+
from src.utils import parse_string, parse_annotations
|
7 |
import os
|
8 |
|
9 |
# --- Function to construct the final query ---
|
|
|
35 |
final_response = f"<video_name>{video_name}</video_name>" + " " + response
|
36 |
return final_response
|
37 |
|
|
|
|
|
38 |
|
39 |
+
def output_to_csv(final_response):
|
40 |
+
# Parse the string to get the content
|
41 |
+
parsed_content = parse_string(final_response, ["video_name", "annotation"])
|
42 |
+
|
43 |
+
# Extract video name (assuming there's only one video name)
|
44 |
+
video_name = parsed_content['video_name'][0] if parsed_content['video_name'] else None
|
45 |
+
|
46 |
+
# Convert the list of annotations into a dictionary
|
47 |
+
annotations_dict = parse_annotations(parsed_content['annotation']) if parsed_content['annotation'] else {}
|
48 |
+
|
49 |
+
# Combine the video name and annotation dictionary into a single row
|
50 |
+
df = pd.DataFrame([{'video_name': video_name, **annotations_dict}])
|
51 |
+
|
52 |
+
return df
|
53 |
|
|
|
|
|
54 |
|
55 |
# Examples for the interface
|
56 |
examples = [
|
57 |
+
["videos/2016-01-01_0100_US_KNBC_Channel_4_News_1867.16-1871.38_now.mp4", True, False, True, False],
|
58 |
+
["videos/2016-01-01_0200_US_KNBC_Channel_4_News_1329.12-1333.29_tonight.mp4", False, True, True, True],
|
59 |
+
["videos/2016-01-01_0830_US_KNBC_Tonight_Show_with_Jimmy_Fallon_725.45-729.76_tonight.mp4", True, False, False, True],
|
60 |
+
["videos/2016-01-01_0200_US_KOCE_The_PBS_Newshour_577.03-581.31_tonight.mp4", False, True, True, False],
|
61 |
+
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4", True, True, False, False],
|
62 |
+
["videos/2016-01-02_0735_US_KCBS_Late_Show_with_Stephen_Colbert_285.94-290.67_this_year.mp4", False, True, True, True],
|
63 |
+
["videos/2016-01-13_2200_US_KTTV-FOX_The_Doctor_Oz_Show_1709.79-1714.17_this_month.mp4", True, False, False, True],
|
64 |
+
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4", False, True, True, False],
|
65 |
+
["videos/2016-01-01_1300_US_KNBC_Today_in_LA_at_5am_12.46-16.95_this_morning.mp4", True, False, False, True],
|
66 |
+
["videos/2016-01-05_0200_US_KNBC_Channel_4_News_1561.29-1565.95_next_week.mp4", False, True, True, False],
|
67 |
+
["videos/2016-01-28_0700_US_KNBC_Channel_4_News_at_11PM_629.56-633.99_in_the_future.mp4", True, False, False, True]
|
68 |
]
|
69 |
|
70 |
# Title, description, and article for the interface
|
|
|
76 |
primary_hue="red",
|
77 |
secondary_hue="red")
|
78 |
|
79 |
+
with gr.Blocks(theme=custom_theme) as demo:
|
80 |
+
gr.Markdown(f"# {title}")
|
81 |
+
gr.Markdown(description)
|
82 |
+
gr.Markdown(article)
|
83 |
+
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
video = gr.Video(label="Video")
|
87 |
+
sitting = gr.Checkbox(label="Sitting/Standing")
|
88 |
+
hands = gr.Checkbox(label="Hands Free/Not Free")
|
89 |
+
location = gr.Checkbox(label="Indoors/Outdoors")
|
90 |
+
screen = gr.Checkbox(label="Screen Interaction")
|
91 |
+
submit_btn = gr.Button("Generate Annotations")
|
92 |
+
generate_csv_btn = gr.Button("Generate CSV")
|
93 |
+
|
94 |
+
with gr.Column():
|
95 |
+
response = gr.Textbox(label="Video Description", show_label=True, show_copy_button=True)
|
96 |
+
csv_output = gr.DataFrame(label="CSV Output", headers=["video_name", "annotation"])
|
97 |
+
|
98 |
+
# Event handling for the Submit button
|
99 |
+
submit_btn.click(
|
100 |
+
fn=process_video_and_questions,
|
101 |
+
inputs=[video, sitting, hands, location, screen],
|
102 |
+
outputs=response
|
103 |
+
)
|
104 |
+
|
105 |
+
# Event handling for the Generate CSV button
|
106 |
+
generate_csv_btn.click(
|
107 |
+
fn=output_to_csv,
|
108 |
+
inputs=response,
|
109 |
+
outputs=csv_output
|
110 |
+
)
|
111 |
+
|
112 |
+
gr.Examples(examples=examples, inputs=[video, sitting, hands, location, screen])
|
113 |
+
|
114 |
+
demo.launch(debug=False)
|