mfarre HF staff commited on
Commit
fc0912b
·
1 Parent(s): 277bb56
Files changed (1) hide show
  1. app.py +37 -29
app.py CHANGED
@@ -16,7 +16,8 @@ import os
16
  from video_highlight_detector import (
17
  load_model,
18
  BatchedVideoHighlightDetector,
19
- get_video_duration_seconds
 
20
  )
21
 
22
  def load_examples(json_path: str) -> dict:
@@ -115,11 +116,6 @@ def create_ui(examples_path: str):
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...",
@@ -133,8 +129,7 @@ def create_ui(examples_path: str):
133
  detector = BatchedVideoHighlightDetector(
134
  model,
135
  processor,
136
- batch_size=8,
137
- progress_callback=progress_callback
138
  )
139
 
140
  yield [
@@ -159,30 +154,43 @@ def create_ui(examples_path: str):
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!",
 
16
  from video_highlight_detector import (
17
  load_model,
18
  BatchedVideoHighlightDetector,
19
+ get_video_duration_seconds,
20
+ get_fixed_30s_segments
21
  )
22
 
23
  def load_examples(json_path: str) -> dict:
 
116
  ]
117
  return
118
 
 
 
 
 
 
119
  # Make accordion visible as soon as processing starts
120
  yield [
121
  "Loading model...",
 
129
  detector = BatchedVideoHighlightDetector(
130
  model,
131
  processor,
132
+ batch_size=8
 
133
  )
134
 
135
  yield [
 
154
  highlights = detector.determine_highlights(video_desc)
155
  formatted_highlights = f"#Highlights to search for: {highlights[:500] + '...' if len(highlights) > 500 else highlights}"
156
 
157
+ # Get all segments
158
+ segments = get_fixed_30s_segments(video)
159
+ total_segments = len(segments)
160
+ kept_segments = []
161
+
162
+ # Process segments in batches with direct UI updates
163
+ for i in range(0, len(segments), detector.batch_size):
164
+ batch_segments = segments[i:i + detector.batch_size]
165
+
166
+ # Update progress
167
+ progress = int((i / total_segments) * 100)
168
+ yield [
169
+ f"Processing segments... {progress}% complete",
170
+ formatted_desc,
171
+ formatted_highlights,
172
+ gr.update(visible=False),
173
+ gr.update(visible=True)
174
+ ]
175
+
176
+ # Process batch
177
+ keep_flags = detector._process_segment_batch(
178
+ video_path=video,
179
+ segments=batch_segments,
180
+ highlight_types=highlights,
181
+ total_segments=total_segments,
182
+ segments_processed=i
183
+ )
184
+
185
+ # Keep track of segments to include
186
+ for segment, keep in zip(batch_segments, keep_flags):
187
+ if keep:
188
+ kept_segments.append(segment)
189
 
190
+ # Create final video
191
  with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as tmp_file:
192
  temp_output = tmp_file.name
193
+ detector._concatenate_scenes(video, kept_segments, temp_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  yield [
196
  "Processing complete!",