mfarre HF staff commited on
Commit
277bb56
·
1 Parent(s): be5d51f
Files changed (1) hide show
  1. app.py +32 -24
app.py CHANGED
@@ -91,11 +91,6 @@ def create_ui(examples_path: str):
91
  video_description = gr.Markdown("", elem_id="video_desc")
92
  highlight_types = gr.Markdown("", elem_id="highlight_types")
93
 
94
- def progress_callback(current, total):
95
- """Callback to update progress percentage"""
96
- percentage = int((current / total) * 100)
97
- return f"Processing segments... {percentage}% complete"
98
-
99
  @spaces.GPU
100
  def on_process(video):
101
  if not video:
@@ -120,6 +115,11 @@ def create_ui(examples_path: str):
120
  ]
121
  return
122
 
 
 
 
 
 
123
  # Make accordion visible as soon as processing starts
124
  yield [
125
  "Loading model...",
@@ -130,8 +130,12 @@ def create_ui(examples_path: str):
130
  ]
131
 
132
  model, processor = load_model()
133
- detector = BatchedVideoHighlightDetector(model, processor, batch_size=8, progress_callback=lambda current, total: print(f"Progress: {current}/{total}")
134
- )
 
 
 
 
135
 
136
  yield [
137
  "Analyzing video content...",
@@ -155,26 +159,30 @@ def create_ui(examples_path: str):
155
  highlights = detector.determine_highlights(video_desc)
156
  formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
157
 
158
- # Get total number of segments for progress tracking
159
- segments = get_fixed_30s_segments(video)
160
- total_segments = len(segments)
161
-
162
- # Process segments in batches with progress updates
163
- for i in range(0, total_segments, detector.batch_size):
164
- current_batch = i + detector.batch_size
165
- progress_msg = progress_callback(min(current_batch, total_segments), total_segments)
166
-
167
- yield [
168
- progress_msg,
169
- formatted_desc,
170
- formatted_highlights,
171
- gr.update(visible=False),
172
- gr.update(visible=True)
173
- ]
174
 
175
  with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
176
  temp_output = tmp_file.name
177
- detector.create_highlight_video(video, temp_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  yield [
180
  "Processing complete!",
 
91
  video_description = gr.Markdown("", elem_id="video_desc")
92
  highlight_types = gr.Markdown("", elem_id="highlight_types")
93
 
 
 
 
 
 
94
  @spaces.GPU
95
  def on_process(video):
96
  if not video:
 
115
  ]
116
  return
117
 
118
+ current_status = ""
119
+ def progress_callback(current, total):
120
+ nonlocal current_status
121
+ current_status = f"Processing segments... {int((current/total) * 100)}% complete"
122
+
123
  # Make accordion visible as soon as processing starts
124
  yield [
125
  "Loading model...",
 
130
  ]
131
 
132
  model, processor = load_model()
133
+ detector = BatchedVideoHighlightDetector(
134
+ model,
135
+ processor,
136
+ batch_size=8,
137
+ progress_callback=progress_callback
138
+ )
139
 
140
  yield [
141
  "Analyzing video content...",
 
159
  highlights = detector.determine_highlights(video_desc)
160
  formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
161
 
162
+ yield [
163
+ "Starting highlight detection...",
164
+ formatted_desc,
165
+ formatted_highlights,
166
+ gr.update(visible=False),
167
+ gr.update(visible=True)
168
+ ]
 
 
 
 
 
 
 
 
 
169
 
170
  with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
171
  temp_output = tmp_file.name
172
+
173
+ # This will now call our progress_callback during processing
174
+ detector.create_highlight_video(video, temp_output)
175
+
176
+ # Keep yielding progress updates while processing
177
+ while current_status:
178
+ yield [
179
+ current_status,
180
+ formatted_desc,
181
+ formatted_highlights,
182
+ gr.update(visible=False),
183
+ gr.update(visible=True)
184
+ ]
185
+ time.sleep(0.1) # Small delay to prevent too frequent updates
186
 
187
  yield [
188
  "Processing complete!",