Spaces:
Runtime error
Runtime error
Miquel Farre
commited on
Commit
·
277bb56
1
Parent(s):
be5d51f
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(
|
| 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 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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!",
|