ManishThota commited on
Commit
08ba28a
1 Parent(s): f4de9a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -71
app.py CHANGED
@@ -1,62 +1,17 @@
1
- # # Importing the requirements
2
- # import warnings
3
- # warnings.filterwarnings("ignore")
4
-
5
- # import gradio as gr
6
- # from src.video_model import describe_video
7
-
8
-
9
- # # Video and text inputs for the interface
10
- # video = gr.Video(label="Video")
11
- # query = gr.Textbox(label="Question", placeholder="Enter your question here")
12
-
13
- # # Output for the interface
14
- # response = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
15
-
16
- # # Examples for the interface
17
- # examples = [
18
- # [
19
- # "videos/2016-01-01_0100_US_KNBC_Channel_4_News_1867.16-1871.38_now.mp4",
20
- # "Here are some frames of a video. Describe this video in detail."
21
- # ],
22
- # [
23
- # "videos/2016-01-01_0200_US_KNBC_Channel_4_News_1329.12-1333.29_tonight.mp4",
24
- # "Here are some frames of a video. Describe this video in detail."
25
- # ],
26
- # [ "videos/2016-01-01_0830_US_KNBC_Tonight_Show_with_Jimmy_Fallon_725.45-729.76_tonight.mp4",
27
- # "Here are some frames of a video. Describe this video in detail."
28
- # ]
29
- # ]
30
-
31
- # # Title, description, and article for the interface
32
- # title = "GSoC Super Raid Annotator"
33
- # description = "Annotate Videos"
34
- # 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>"
35
-
36
-
37
- # # Launch the interface
38
- # interface = gr.Interface(
39
- # fn=describe_video,
40
- # inputs=[video, query],
41
- # outputs=response,
42
- # examples=examples,
43
- # title=title,
44
- # description=description,
45
- # article=article,
46
- # theme="Soft",
47
- # allow_flagging="never",
48
- # )
49
- # interface.launch(debug=False)
50
-
51
-
52
  import warnings
53
  warnings.filterwarnings("ignore")
54
  import gradio as gr
55
- from src.video_model import describe_video # Assuming this function processes the video and query
 
56
 
57
- # --- Function to construct the final query ---
58
- def process_video_and_questions(video, sitting, hands, location, screen):
59
- query = "Describe this video in detail and answer the questions"
 
 
 
 
 
60
  additional_info = []
61
  if sitting:
62
  additional_info.append("Is the subject in the video standing or sitting?")
@@ -66,23 +21,30 @@ def process_video_and_questions(video, sitting, hands, location, screen):
66
  additional_info.append("Is the subject present indoors or outdoors?")
67
  if screen:
68
  additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
69
-
70
  final_query = query + " " + " ".join(additional_info)
71
- # Assuming your describe_video function handles the video processing
72
- response = describe_video(video, final_query)
73
- return response
74
 
75
- # Video and text inputs for the interface
76
- video = gr.Video(label="Video")
 
 
 
 
 
77
 
78
- # Options as checkboxes
79
  sitting = gr.Checkbox(label="Sitting/Standing")
80
  hands = gr.Checkbox(label="Hands Free/Not Free")
81
  location = gr.Checkbox(label="Indoors/Outdoors")
82
  screen = gr.Checkbox(label="Screen Interaction")
83
 
84
- # Output for the interface
85
- response = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
 
 
86
 
87
  # Examples for the interface
88
  examples = [
@@ -104,17 +66,15 @@ title = "GSoC Super Raid Annotator"
104
  description = "Annotate Videos"
105
  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>"
106
 
107
-
108
  custom_theme = gr.themes.Soft(
109
- # Set the primary hue of the Soft theme to your red color
110
  primary_hue="red",
111
- secondary_hue="red")
 
112
 
113
- # Launch the interface
114
  interface = gr.Interface(
115
- fn=process_video_and_questions, # Updated function to handle the query construction
116
- inputs=[video, sitting, hands, location, screen],
117
- outputs=response,
118
  examples=examples,
119
  title=title,
120
  description=description,
@@ -122,4 +82,8 @@ interface = gr.Interface(
122
  theme=custom_theme,
123
  allow_flagging="never",
124
  )
 
 
 
 
125
  interface.launch(debug=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import warnings
2
  warnings.filterwarnings("ignore")
3
  import gradio as gr
4
+ from src.video_model import describe_video # Your video processing function
5
+ from src.text_processor import process_description # Your text processing function
6
 
7
+ # --- Global variable to store the prediction ---
8
+ prediction = None
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
  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
+ prediction = describe_video(video, final_query)
27
+ # Enable the "Process Text" button
28
+ return gr.update(visible=True), prediction
29
 
30
+ # --- Function to trigger text processing ---
31
+ def process_and_display_text():
32
+ global prediction
33
+ json_response = process_description(prediction)
34
+ return json_response
35
+
36
+ # ... (Gradio interface code) ...
37
 
38
+ video = gr.Video(label="Video")
39
  sitting = gr.Checkbox(label="Sitting/Standing")
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
  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
  interface = gr.Interface(
75
+ fn=process_video,
76
+ inputs=[video, sitting, hands, location, screen],
77
+ outputs=[process_button, video_description],
78
  examples=examples,
79
  title=title,
80
  description=description,
 
82
  theme=custom_theme,
83
  allow_flagging="never",
84
  )
85
+
86
+ # Click event for the "Process Text" button
87
+ process_button.click(fn=process_and_display_text, outputs=json_output)
88
+
89
  interface.launch(debug=False)