Updated html video viewer to gradio video viewer
Browse files
app.py
CHANGED
|
@@ -158,10 +158,20 @@ def process_video(
|
|
| 158 |
progress: Gradio progress tracker
|
| 159 |
|
| 160 |
Returns:
|
| 161 |
-
Tuple of (status_message, clip1, clip2, clip3, log_text, metrics_text)
|
| 162 |
"""
|
| 163 |
if video_file is None:
|
| 164 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
log_messages = []
|
| 167 |
|
|
@@ -181,7 +191,17 @@ def process_video(
|
|
| 181 |
# Validate video
|
| 182 |
validation = validate_video_file(video_file)
|
| 183 |
if not validation.is_valid:
|
| 184 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
log(f"Video size: {validation.file_size / (1024*1024):.1f} MB")
|
| 187 |
|
|
@@ -192,22 +212,14 @@ def process_video(
|
|
| 192 |
log("TEST MODE: Skipping processing, showing mock highlights")
|
| 193 |
progress(0.5, desc="Generating test highlights...")
|
| 194 |
|
| 195 |
-
#
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
<strong>Score:</strong> {95-i*5:.1f} |
|
| 204 |
-
<strong>Domain:</strong> {domain}
|
| 205 |
-
</div>
|
| 206 |
-
<video width="100%" controls style="border-radius: 4px;">
|
| 207 |
-
<source src="{video_file}" type="video/mp4">
|
| 208 |
-
</video>
|
| 209 |
-
</div>
|
| 210 |
-
'''
|
| 211 |
|
| 212 |
status = f"TEST MODE: Generated {int(num_clips)} mock highlight clips from {Path(video_file).name}"
|
| 213 |
metrics_output = f"""
|
|
@@ -221,7 +233,17 @@ Test Mode Metrics:
|
|
| 221 |
""".strip()
|
| 222 |
|
| 223 |
progress(1.0, desc="Test complete!")
|
| 224 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
###----------------------------------------------------------------------------------------------------------------------
|
| 226 |
# Validate reference image if provided
|
| 227 |
ref_path = None
|
|
@@ -304,35 +326,57 @@ Test Mode Metrics:
|
|
| 304 |
pipeline.cleanup()
|
| 305 |
progress(1.0, desc="Done!")
|
| 306 |
|
| 307 |
-
#
|
| 308 |
-
|
| 309 |
-
for i
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
| 325 |
else:
|
| 326 |
log(f"Processing failed: {result.error_message}")
|
| 327 |
pipeline.cleanup()
|
| 328 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
except Exception as e:
|
| 331 |
error_msg = f"Unexpected error: {str(e)}"
|
| 332 |
log(error_msg)
|
| 333 |
log(traceback.format_exc())
|
| 334 |
logger.exception("Pipeline error")
|
| 335 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
|
| 338 |
# =============================================================================
|
|
@@ -865,6 +909,14 @@ with gr.Blocks(
|
|
| 865 |
gr.Markdown("#### Extracted Clips")
|
| 866 |
clips_output = gr.HTML(label="Extracted Clips")
|
| 867 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
with gr.Accordion("Processing Log", open=True):
|
| 869 |
log_output = gr.Textbox(
|
| 870 |
label="Log",
|
|
@@ -896,8 +948,13 @@ with gr.Blocks(
|
|
| 896 |
outputs=[
|
| 897 |
status_output,
|
| 898 |
clips_output,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 899 |
log_output,
|
| 900 |
-
metrics_output
|
| 901 |
],
|
| 902 |
show_progress="full"
|
| 903 |
)
|
|
|
|
| 158 |
progress: Gradio progress tracker
|
| 159 |
|
| 160 |
Returns:
|
| 161 |
+
Tuple of (status_message, clips_html_update, clip1, clip2, clip3, clip4, clip5, log_text, metrics_text)
|
| 162 |
"""
|
| 163 |
if video_file is None:
|
| 164 |
+
return (
|
| 165 |
+
"Please upload a video first.",
|
| 166 |
+
gr.update(value="", visible=False),
|
| 167 |
+
gr.update(value=None, visible=False),
|
| 168 |
+
gr.update(value=None, visible=False),
|
| 169 |
+
gr.update(value=None, visible=False),
|
| 170 |
+
gr.update(value=None, visible=False),
|
| 171 |
+
gr.update(value=None, visible=False),
|
| 172 |
+
"",
|
| 173 |
+
"",
|
| 174 |
+
)
|
| 175 |
|
| 176 |
log_messages = []
|
| 177 |
|
|
|
|
| 191 |
# Validate video
|
| 192 |
validation = validate_video_file(video_file)
|
| 193 |
if not validation.is_valid:
|
| 194 |
+
return (
|
| 195 |
+
f"Error: {validation.error_message}",
|
| 196 |
+
gr.update(value="", visible=False),
|
| 197 |
+
gr.update(value=None, visible=False),
|
| 198 |
+
gr.update(value=None, visible=False),
|
| 199 |
+
gr.update(value=None, visible=False),
|
| 200 |
+
gr.update(value=None, visible=False),
|
| 201 |
+
gr.update(value=None, visible=False),
|
| 202 |
+
"\n".join(log_messages),
|
| 203 |
+
"",
|
| 204 |
+
)
|
| 205 |
|
| 206 |
log(f"Video size: {validation.file_size / (1024*1024):.1f} MB")
|
| 207 |
|
|
|
|
| 212 |
log("TEST MODE: Skipping processing, showing mock highlights")
|
| 213 |
progress(0.5, desc="Generating test highlights...")
|
| 214 |
|
| 215 |
+
# Prepare updates: show only the requested number of clips (use the uploaded video as source)
|
| 216 |
+
clip_updates = []
|
| 217 |
+
requested = min(int(num_clips), 5)
|
| 218 |
+
for i in range(5):
|
| 219 |
+
if i < requested:
|
| 220 |
+
clip_updates.append(gr.update(value=str(video_path), visible=True))
|
| 221 |
+
else:
|
| 222 |
+
clip_updates.append(gr.update(value=None, visible=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
status = f"TEST MODE: Generated {int(num_clips)} mock highlight clips from {Path(video_file).name}"
|
| 225 |
metrics_output = f"""
|
|
|
|
| 233 |
""".strip()
|
| 234 |
|
| 235 |
progress(1.0, desc="Test complete!")
|
| 236 |
+
return (
|
| 237 |
+
status,
|
| 238 |
+
gr.update(value="", visible=False),
|
| 239 |
+
clip_updates[0],
|
| 240 |
+
clip_updates[1],
|
| 241 |
+
clip_updates[2],
|
| 242 |
+
clip_updates[3],
|
| 243 |
+
clip_updates[4],
|
| 244 |
+
"\n".join(log_messages),
|
| 245 |
+
metrics_output,
|
| 246 |
+
)
|
| 247 |
###----------------------------------------------------------------------------------------------------------------------
|
| 248 |
# Validate reference image if provided
|
| 249 |
ref_path = None
|
|
|
|
| 326 |
pipeline.cleanup()
|
| 327 |
progress(1.0, desc="Done!")
|
| 328 |
|
| 329 |
+
# Prepare updates: show only the extracted clips (up to 5), hide the rest
|
| 330 |
+
clip_updates = []
|
| 331 |
+
for i in range(5):
|
| 332 |
+
if i < len(clip_paths):
|
| 333 |
+
clip_updates.append(gr.update(value=str(clip_paths[i]), visible=True))
|
| 334 |
+
else:
|
| 335 |
+
clip_updates.append(gr.update(value=None, visible=False))
|
| 336 |
+
|
| 337 |
+
# Clear the HTML preview (`clips_output`) when returning final video outputs
|
| 338 |
+
return (
|
| 339 |
+
status,
|
| 340 |
+
gr.update(value="", visible=False),
|
| 341 |
+
clip_updates[0],
|
| 342 |
+
clip_updates[1],
|
| 343 |
+
clip_updates[2],
|
| 344 |
+
clip_updates[3],
|
| 345 |
+
clip_updates[4],
|
| 346 |
+
"\n".join(log_messages),
|
| 347 |
+
metrics_output,
|
| 348 |
+
)
|
| 349 |
else:
|
| 350 |
log(f"Processing failed: {result.error_message}")
|
| 351 |
pipeline.cleanup()
|
| 352 |
+
return (
|
| 353 |
+
f"Error: {result.error_message}",
|
| 354 |
+
gr.update(value="", visible=False),
|
| 355 |
+
gr.update(value=None, visible=False),
|
| 356 |
+
gr.update(value=None, visible=False),
|
| 357 |
+
gr.update(value=None, visible=False),
|
| 358 |
+
gr.update(value=None, visible=False),
|
| 359 |
+
gr.update(value=None, visible=False),
|
| 360 |
+
"\n".join(log_messages),
|
| 361 |
+
"",
|
| 362 |
+
)
|
| 363 |
|
| 364 |
except Exception as e:
|
| 365 |
error_msg = f"Unexpected error: {str(e)}"
|
| 366 |
log(error_msg)
|
| 367 |
log(traceback.format_exc())
|
| 368 |
logger.exception("Pipeline error")
|
| 369 |
+
return (
|
| 370 |
+
error_msg,
|
| 371 |
+
gr.update(value="", visible=False),
|
| 372 |
+
gr.update(value=None, visible=False),
|
| 373 |
+
gr.update(value=None, visible=False),
|
| 374 |
+
gr.update(value=None, visible=False),
|
| 375 |
+
gr.update(value=None, visible=False),
|
| 376 |
+
gr.update(value=None, visible=False),
|
| 377 |
+
"\n".join(log_messages),
|
| 378 |
+
"",
|
| 379 |
+
)
|
| 380 |
|
| 381 |
|
| 382 |
# =============================================================================
|
|
|
|
| 909 |
gr.Markdown("#### Extracted Clips")
|
| 910 |
clips_output = gr.HTML(label="Extracted Clips")
|
| 911 |
|
| 912 |
+
# Pre-created video outputs (max 5) - will be populated by the callback
|
| 913 |
+
with gr.Row():
|
| 914 |
+
clip_video1 = gr.Video(label="Clip 1", interactive=False, visible=False)
|
| 915 |
+
clip_video2 = gr.Video(label="Clip 2", interactive=False, visible=False)
|
| 916 |
+
clip_video3 = gr.Video(label="Clip 3", interactive=False, visible=False)
|
| 917 |
+
clip_video4 = gr.Video(label="Clip 4", interactive=False, visible=False)
|
| 918 |
+
clip_video5 = gr.Video(label="Clip 5", interactive=False, visible=False)
|
| 919 |
+
|
| 920 |
with gr.Accordion("Processing Log", open=True):
|
| 921 |
log_output = gr.Textbox(
|
| 922 |
label="Log",
|
|
|
|
| 948 |
outputs=[
|
| 949 |
status_output,
|
| 950 |
clips_output,
|
| 951 |
+
clip_video1,
|
| 952 |
+
clip_video2,
|
| 953 |
+
clip_video3,
|
| 954 |
+
clip_video4,
|
| 955 |
+
clip_video5,
|
| 956 |
log_output,
|
| 957 |
+
metrics_output,
|
| 958 |
],
|
| 959 |
show_progress="full"
|
| 960 |
)
|