Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,15 +53,15 @@ def update_progress(progress: PipelineProgress) -> None:
|
|
| 53 |
|
| 54 |
|
| 55 |
def process_video(
|
| 56 |
-
video_file
|
| 57 |
-
api_key
|
| 58 |
-
domain
|
| 59 |
-
num_clips
|
| 60 |
-
clip_duration
|
| 61 |
-
reference_image
|
| 62 |
-
custom_prompt
|
| 63 |
-
progress
|
| 64 |
-
)
|
| 65 |
"""
|
| 66 |
Main processing function for Gradio interface.
|
| 67 |
|
|
@@ -84,14 +84,21 @@ def process_video(
|
|
| 84 |
|
| 85 |
log_messages = []
|
| 86 |
|
| 87 |
-
def log(msg
|
| 88 |
log_messages.append(f"[{time.strftime('%H:%M:%S')}] {msg}")
|
| 89 |
logger.info(msg)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
try:
|
| 92 |
# Validate inputs
|
| 93 |
log("Validating inputs...")
|
| 94 |
-
|
| 95 |
|
| 96 |
if not video_file:
|
| 97 |
return [], "❌ Error: No video file provided", "\n".join(log_messages)
|
|
@@ -130,12 +137,12 @@ def process_video(
|
|
| 130 |
log(f"Output directory: {output_dir}")
|
| 131 |
|
| 132 |
# Initialize pipeline with progress callback
|
| 133 |
-
def progress_callback(p
|
| 134 |
update_progress(p)
|
| 135 |
-
|
| 136 |
|
| 137 |
log("Initializing pipeline...")
|
| 138 |
-
|
| 139 |
|
| 140 |
_current_pipeline = PipelineOrchestrator(
|
| 141 |
progress_callback=progress_callback
|
|
@@ -338,16 +345,19 @@ def create_interface() -> gr.Blocks:
|
|
| 338 |
# Event handlers
|
| 339 |
def on_process(video, api_key, domain, num_clips, duration, ref_img, prompt, progress=gr.Progress()):
|
| 340 |
"""Handle process button click."""
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
| 344 |
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
|
| 350 |
-
|
|
|
|
|
|
|
| 351 |
|
| 352 |
process_btn.click(
|
| 353 |
fn=on_process,
|
|
@@ -361,7 +371,6 @@ def create_interface() -> gr.Blocks:
|
|
| 361 |
custom_prompt,
|
| 362 |
],
|
| 363 |
outputs=[status_output, clip_gallery, log_output],
|
| 364 |
-
show_progress=True,
|
| 365 |
)
|
| 366 |
|
| 367 |
return demo
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
def process_video(
|
| 56 |
+
video_file,
|
| 57 |
+
api_key,
|
| 58 |
+
domain,
|
| 59 |
+
num_clips,
|
| 60 |
+
clip_duration,
|
| 61 |
+
reference_image,
|
| 62 |
+
custom_prompt,
|
| 63 |
+
progress=None,
|
| 64 |
+
):
|
| 65 |
"""
|
| 66 |
Main processing function for Gradio interface.
|
| 67 |
|
|
|
|
| 84 |
|
| 85 |
log_messages = []
|
| 86 |
|
| 87 |
+
def log(msg):
|
| 88 |
log_messages.append(f"[{time.strftime('%H:%M:%S')}] {msg}")
|
| 89 |
logger.info(msg)
|
| 90 |
|
| 91 |
+
def update_prog(val, desc=""):
|
| 92 |
+
if progress is not None:
|
| 93 |
+
try:
|
| 94 |
+
progress(val, desc=desc)
|
| 95 |
+
except:
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
try:
|
| 99 |
# Validate inputs
|
| 100 |
log("Validating inputs...")
|
| 101 |
+
update_prog(0.02, "Validating inputs...")
|
| 102 |
|
| 103 |
if not video_file:
|
| 104 |
return [], "❌ Error: No video file provided", "\n".join(log_messages)
|
|
|
|
| 137 |
log(f"Output directory: {output_dir}")
|
| 138 |
|
| 139 |
# Initialize pipeline with progress callback
|
| 140 |
+
def progress_callback(p):
|
| 141 |
update_progress(p)
|
| 142 |
+
update_prog(p.progress, p.message)
|
| 143 |
|
| 144 |
log("Initializing pipeline...")
|
| 145 |
+
update_prog(0.05, "Initializing pipeline...")
|
| 146 |
|
| 147 |
_current_pipeline = PipelineOrchestrator(
|
| 148 |
progress_callback=progress_callback
|
|
|
|
| 345 |
# Event handlers
|
| 346 |
def on_process(video, api_key, domain, num_clips, duration, ref_img, prompt, progress=gr.Progress()):
|
| 347 |
"""Handle process button click."""
|
| 348 |
+
try:
|
| 349 |
+
clips, status, logs = process_video(
|
| 350 |
+
video, api_key, domain, num_clips, duration, ref_img, prompt, progress
|
| 351 |
+
)
|
| 352 |
|
| 353 |
+
# Convert clip paths to gallery format
|
| 354 |
+
gallery_items = []
|
| 355 |
+
for clip_path in clips:
|
| 356 |
+
gallery_items.append((clip_path, f"Clip {len(gallery_items)+1}"))
|
| 357 |
|
| 358 |
+
return status, gallery_items, logs
|
| 359 |
+
except Exception as e:
|
| 360 |
+
return f"❌ Error: {str(e)}", [], f"Error: {str(e)}"
|
| 361 |
|
| 362 |
process_btn.click(
|
| 363 |
fn=on_process,
|
|
|
|
| 371 |
custom_prompt,
|
| 372 |
],
|
| 373 |
outputs=[status_output, clip_gallery, log_output],
|
|
|
|
| 374 |
)
|
| 375 |
|
| 376 |
return demo
|