Spaces:
Runtime error
Runtime error
ManishThota
commited on
Commit
•
b3ca871
1
Parent(s):
0b7e27f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import warnings
|
2 |
+
warnings.filterwarnings("ignore")
|
3 |
+
import gradio as gr
|
4 |
+
from src.video_model import describe_video # Assuming this function processes the video and query
|
5 |
+
|
6 |
+
# --- Function to construct the final query ---
|
7 |
+
def process_video_and_questions(video, sitting, hands, location, screen):
|
8 |
+
query = "Describe this video in detail and answer the questions"
|
9 |
+
additional_info = []
|
10 |
+
if sitting:
|
11 |
+
additional_info.append("Is the subject in the video standing or sitting?")
|
12 |
+
if hands:
|
13 |
+
additional_info.append("Is the subject holding any object in their hands, if so the hands are not free else they are free?")
|
14 |
+
if location:
|
15 |
+
additional_info.append("Is the subject present indoors or outdoors?")
|
16 |
+
if screen:
|
17 |
+
additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
|
18 |
+
end_query = "Provide the results in JSON format with 0 being False and 1 being True"
|
19 |
+
final_query = query + " " + " ".join(additional_info)
|
20 |
+
# Assuming your describe_video function handles the video processing
|
21 |
+
response = describe_video(video, final_query)
|
22 |
+
return response
|
23 |
+
|
24 |
+
# Video and text inputs for the interface
|
25 |
+
video = gr.Video(label="Video")
|
26 |
+
|
27 |
+
# Options as checkboxes
|
28 |
+
sitting = gr.Checkbox(label="Sitting/Standing")
|
29 |
+
hands = gr.Checkbox(label="Hands Free/Not Free")
|
30 |
+
location = gr.Checkbox(label="Indoors/Outdoors")
|
31 |
+
screen = gr.Checkbox(label="Screen Interaction")
|
32 |
+
|
33 |
+
# Output for the interface
|
34 |
+
response = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
|
35 |
+
|
36 |
+
# Examples for the interface
|
37 |
+
examples = [
|
38 |
+
["videos/2016-01-01_0100_US_KNBC_Channel_4_News_1867.16-1871.38_now.mp4",],
|
39 |
+
["videos/2016-01-01_0200_US_KNBC_Channel_4_News_1329.12-1333.29_tonight.mp4",],
|
40 |
+
["videos/2016-01-01_0830_US_KNBC_Tonight_Show_with_Jimmy_Fallon_725.45-729.76_tonight.mp4",],
|
41 |
+
["videos/2016-01-01_0200_US_KOCE_The_PBS_Newshour_577.03-581.31_tonight.mp4"],
|
42 |
+
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4"],
|
43 |
+
["videos/2016-01-02_0735_US_KCBS_Late_Show_with_Stephen_Colbert_285.94-290.67_this_year.mp4"],
|
44 |
+
["videos/2016-01-13_2200_US_KTTV-FOX_The_Doctor_Oz_Show_1709.79-1714.17_this_month.mp4"],
|
45 |
+
["videos/2016-01-01_1400_US_KTTV-FOX_Morning_News_at_6AM_1842.36-1846.68_this_year.mp4"],
|
46 |
+
["videos/2016-01-01_1300_US_KNBC_Today_in_LA_at_5am_12.46-16.95_this_morning.mp4"],
|
47 |
+
["videos/2016-01-05_0200_US_KNBC_Channel_4_News_1561.29-1565.95_next_week.mp4"],
|
48 |
+
["videos/2016-01-28_0700_US_KNBC_Channel_4_News_at_11PM_629.56-633.99_in_the_future.mp4"]
|
49 |
+
]
|
50 |
+
|
51 |
+
# Title, description, and article for the interface
|
52 |
+
title = "GSoC Super Raid Annotator"
|
53 |
+
description = "Annotate Videos"
|
54 |
+
article = "<p style='text-align: center'><a href='https://github.com/OpenBMB/MiniCPM-V' target='_blank'>Model GitHub Repo</a> | <a href='https://huggingface.co/openbmb/MiniCPM-V-2_6' target='_blank'>Model Page</a></p>"
|
55 |
+
|
56 |
+
|
57 |
+
custom_theme = gr.themes.Soft(
|
58 |
+
# Set the primary hue of the Soft theme to your red color
|
59 |
+
primary_hue="red",
|
60 |
+
secondary_hue="red")
|
61 |
+
|
62 |
+
# Launch the interface
|
63 |
+
interface = gr.Interface(
|
64 |
+
fn=process_video_and_questions, # Updated function to handle the query construction
|
65 |
+
inputs=[video, sitting, hands, location, screen],
|
66 |
+
outputs=response,
|
67 |
+
examples=examples,
|
68 |
+
title=title,
|
69 |
+
description=description,
|
70 |
+
article=article,
|
71 |
+
theme=custom_theme,
|
72 |
+
allow_flagging="never",
|
73 |
+
)
|
74 |
+
interface.launch(debug=False)
|