mfarre HF staff commited on
Commit
8323202
·
1 Parent(s): 0cb8d8c
Files changed (1) hide show
  1. app.py +57 -57
app.py CHANGED
@@ -95,91 +95,91 @@ def create_ui(examples_path: str):
95
  @spaces.GPU
96
  def on_process(video):
97
  if not video:
98
- yield {
99
- "status": "Please upload a video", # Changed to string key
100
- "video_description": gr.update(value=""), # Added gr.update
101
- "highlight_types": gr.update(value=""), # Added gr.update
102
- "output_video": gr.update(visible=False),
103
- "analysis_accordion": gr.update(visible=False)
104
- }
105
  return
106
 
107
  try:
108
  duration = get_video_duration_seconds(video)
109
  if duration > 1200: # 20 minutes
110
- yield {
111
- "status": "Video must be shorter than 20 minutes",
112
- "video_description": gr.update(value=""),
113
- "highlight_types": gr.update(value=""),
114
- "output_video": gr.update(visible=False),
115
- "analysis_accordion": gr.update(visible=False)
116
- }
117
  return
118
 
119
  # Make accordion visible as soon as processing starts
120
- yield {
121
- "status": "Loading model...",
122
- "video_description": gr.update(value=""),
123
- "highlight_types": gr.update(value=""),
124
- "output_video": gr.update(visible=False),
125
- "analysis_accordion": gr.update(visible=True)
126
- }
127
 
128
  model, processor = load_model()
129
  detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
130
 
131
- yield {
132
- "status": "Analyzing video content...",
133
- "video_description": gr.update(value=""),
134
- "highlight_types": gr.update(value=""),
135
- "output_video": gr.update(visible=False),
136
- "analysis_accordion": gr.update(visible=True)
137
- }
138
 
139
  video_desc = detector.analyze_video_content(video)
140
  formatted_desc = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
141
 
142
  # Update description as soon as it's available
143
- yield {
144
- "status": "Determining highlight types...",
145
- "video_description": gr.update(value=formatted_desc),
146
- "highlight_types": gr.update(value=""),
147
- "output_video": gr.update(visible=False),
148
- "analysis_accordion": gr.update(visible=True)
149
- }
150
 
151
  highlights = detector.determine_highlights(video_desc)
152
  formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
153
 
154
  # Update highlights as soon as they're available
155
- yield {
156
- "status": "Detecting and extracting highlights...",
157
- "video_description": gr.update(value=formatted_desc),
158
- "highlight_types": gr.update(value=formatted_highlights),
159
- "output_video": gr.update(visible=False),
160
- "analysis_accordion": gr.update(visible=True)
161
- }
162
 
163
  with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
164
  temp_output = tmp_file.name
165
  detector.create_highlight_video(video, temp_output)
166
 
167
- yield {
168
- "status": "Processing complete!",
169
- "video_description": gr.update(value=formatted_desc),
170
- "highlight_types": gr.update(value=formatted_highlights),
171
- "output_video": gr.update(value=temp_output, visible=True),
172
- "analysis_accordion": gr.update(visible=True)
173
- }
174
 
175
  except Exception as e:
176
- yield {
177
- "status": f"Error processing video: {str(e)}",
178
- "video_description": gr.update(value=""),
179
- "highlight_types": gr.update(value=""),
180
- "output_video": gr.update(visible=False),
181
- "analysis_accordion": gr.update(visible=False)
182
- }
183
 
184
  process_btn.click(
185
  on_process,
@@ -191,7 +191,7 @@ def create_ui(examples_path: str):
191
  output_video,
192
  analysis_accordion
193
  ],
194
- queue=True, # Added queue=True
195
  )
196
 
197
  return app
 
95
  @spaces.GPU
96
  def on_process(video):
97
  if not video:
98
+ yield [
99
+ "Please upload a video", # status
100
+ "", # video_description
101
+ "", # highlight_types
102
+ gr.update(visible=False), # output_video
103
+ gr.update(visible=False) # analysis_accordion
104
+ ]
105
  return
106
 
107
  try:
108
  duration = get_video_duration_seconds(video)
109
  if duration > 1200: # 20 minutes
110
+ yield [
111
+ "Video must be shorter than 20 minutes",
112
+ "",
113
+ "",
114
+ gr.update(visible=False),
115
+ gr.update(visible=False)
116
+ ]
117
  return
118
 
119
  # Make accordion visible as soon as processing starts
120
+ yield [
121
+ "Loading model...",
122
+ "",
123
+ "",
124
+ gr.update(visible=False),
125
+ gr.update(visible=True)
126
+ ]
127
 
128
  model, processor = load_model()
129
  detector = BatchedVideoHighlightDetector(model, processor, batch_size=8)
130
 
131
+ yield [
132
+ "Analyzing video content...",
133
+ "",
134
+ "",
135
+ gr.update(visible=False),
136
+ gr.update(visible=True)
137
+ ]
138
 
139
  video_desc = detector.analyze_video_content(video)
140
  formatted_desc = f"#Summary: {video_desc[:500] + '...' if len(video_desc) > 500 else video_desc}"
141
 
142
  # Update description as soon as it's available
143
+ yield [
144
+ "Determining highlight types...",
145
+ formatted_desc,
146
+ "",
147
+ gr.update(visible=False),
148
+ gr.update(visible=True)
149
+ ]
150
 
151
  highlights = detector.determine_highlights(video_desc)
152
  formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
153
 
154
  # Update highlights as soon as they're available
155
+ yield [
156
+ "Detecting and extracting highlights...",
157
+ formatted_desc,
158
+ formatted_highlights,
159
+ gr.update(visible=False),
160
+ gr.update(visible=True)
161
+ ]
162
 
163
  with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
164
  temp_output = tmp_file.name
165
  detector.create_highlight_video(video, temp_output)
166
 
167
+ yield [
168
+ "Processing complete!",
169
+ formatted_desc,
170
+ formatted_highlights,
171
+ gr.update(value=temp_output, visible=True),
172
+ gr.update(visible=True)
173
+ ]
174
 
175
  except Exception as e:
176
+ yield [
177
+ f"Error processing video: {str(e)}",
178
+ "",
179
+ "",
180
+ gr.update(visible=False),
181
+ gr.update(visible=False)
182
+ ]
183
 
184
  process_btn.click(
185
  on_process,
 
191
  output_video,
192
  analysis_accordion
193
  ],
194
+ queue=True,
195
  )
196
 
197
  return app