Chaitanya-aitf commited on
Commit
29219bd
·
verified ·
1 Parent(s): 05f5f5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -53,15 +53,15 @@ def update_progress(progress: PipelineProgress) -> None:
53
 
54
 
55
  def process_video(
56
- video_file: str,
57
- api_key: str,
58
- domain: str,
59
- num_clips: int,
60
- clip_duration: float,
61
- reference_image: Optional[str],
62
- custom_prompt: str,
63
- progress: gr.Progress = gr.Progress(),
64
- ) -> Tuple[List[str], str, str]:
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: str) -> None:
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
- progress(0.02, desc="Validating inputs...")
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: PipelineProgress):
134
  update_progress(p)
135
- progress(p.progress, desc=p.message)
136
 
137
  log("Initializing pipeline...")
138
- progress(0.05, desc="Initializing pipeline...")
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
- clips, status, logs = process_video(
342
- video, api_key, domain, num_clips, duration, ref_img, prompt, progress
343
- )
 
344
 
345
- # Convert clip paths to gallery format
346
- gallery_items = []
347
- for clip_path in clips:
348
- gallery_items.append((clip_path, f"Clip {len(gallery_items)+1}"))
349
 
350
- return status, gallery_items, logs
 
 
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