Spaces:
Runtime error
Runtime error
ManishThota
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,11 @@
|
|
1 |
import warnings
|
2 |
warnings.filterwarnings("ignore")
|
3 |
import gradio as gr
|
4 |
-
from src.video_model import describe_video #
|
5 |
-
from src.text_processor import process_description # Your text processing function
|
6 |
|
7 |
-
# ---
|
8 |
-
|
9 |
-
|
10 |
-
# --- Function to handle video processing ---
|
11 |
-
def process_video(video, sitting, hands, location, screen):
|
12 |
-
global prediction # Access the global prediction variable
|
13 |
-
|
14 |
-
query = "Describe this video in detail and answer the questions."
|
15 |
additional_info = []
|
16 |
if sitting:
|
17 |
additional_info.append("Is the subject in the video standing or sitting?")
|
@@ -21,30 +15,23 @@ def process_video(video, sitting, hands, location, screen):
|
|
21 |
additional_info.append("Is the subject present indoors or outdoors?")
|
22 |
if screen:
|
23 |
additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
|
24 |
-
|
25 |
final_query = query + " " + " ".join(additional_info)
|
26 |
-
|
27 |
-
|
28 |
-
return
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
global prediction
|
33 |
-
json_response = process_description(prediction)
|
34 |
-
return json_response
|
35 |
|
36 |
-
#
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
#hands = gr.Checkbox(label="Hands Free/Not Free")
|
41 |
-
#location = gr.Checkbox(label="Indoors/Outdoors")
|
42 |
-
#screen = gr.Checkbox(label="Screen Interaction")
|
43 |
-
|
44 |
-
# Output components
|
45 |
-
#video_description = gr.Textbox(label="Video Description")
|
46 |
-
#json_output = gr.JSON(label="JSON Output")
|
47 |
-
#process_button = gr.Button("Process Text", visible=False)
|
48 |
|
49 |
# Examples for the interface
|
50 |
examples = [
|
@@ -66,39 +53,22 @@ title = "GSoC Super Raid Annotator"
|
|
66 |
description = "Annotate Videos"
|
67 |
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>"
|
68 |
|
|
|
69 |
custom_theme = gr.themes.Soft(
|
|
|
70 |
primary_hue="red",
|
71 |
-
secondary_hue="red"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
)
|
73 |
-
|
74 |
-
|
75 |
-
with gr.Blocks(theme=custom_theme) as demo: # Use 'with' for gr.Blocks
|
76 |
-
video = gr.Video(label="Video")
|
77 |
-
sitting = gr.Checkbox(label="Sitting/Standing")
|
78 |
-
hands = gr.Checkbox(label="Hands Free/Not Free")
|
79 |
-
location = gr.Checkbox(label="Indoors/Outdoors")
|
80 |
-
screen = gr.Checkbox(label="Screen Interaction")
|
81 |
-
|
82 |
-
# Output components
|
83 |
-
video_description = gr.Textbox(label="Video Description")
|
84 |
-
json_output = gr.JSON(label="JSON Output")
|
85 |
-
process_button = gr.Button("Process Text", visible=False)
|
86 |
-
|
87 |
-
# --- Connect inputs and outputs within gr.Blocks ---
|
88 |
-
interface = gr.Interface(
|
89 |
-
fn=process_video,
|
90 |
-
inputs=[video, sitting, hands, location, screen],
|
91 |
-
outputs=[process_button, video_description],
|
92 |
-
examples=examples,
|
93 |
-
title=title,
|
94 |
-
description=description,
|
95 |
-
article=article,
|
96 |
-
allow_flagging="never",
|
97 |
-
)
|
98 |
-
interface.launch(debug=False)
|
99 |
-
|
100 |
-
# --- Button click event handler ---
|
101 |
-
process_button.click(fn=process_and_display_text, outputs=json_output)# Click event for the "Process Text" button
|
102 |
-
|
103 |
-
|
104 |
interface.launch(debug=False)
|
|
|
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?")
|
|
|
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 |
+
|
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 = [
|
|
|
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)
|