gokaygokay commited on
Commit
72fd6ee
1 Parent(s): ca58083

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -275,7 +275,7 @@ def frames_to_video(input_folder, output_path, fps, original_video_path):
275
  os.remove(temp_output_path)
276
 
277
  @timer_func
278
- def process_video(input_video, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames=None, frame_interval=1, preserve_frames=False, progress=gr.Progress()):
279
  abort_event.clear() # Clear the abort flag at the start of a new job
280
  print("Starting video processing...")
281
  model_manager.load_models(progress) # Ensure models are loaded
@@ -287,14 +287,15 @@ def process_video(input_video, resolution, num_inference_steps, strength, hdr, g
287
 
288
  # Save job config
289
  config = {
290
- "resolution": resolution,
291
- "num_inference_steps": num_inference_steps,
292
- "strength": strength,
293
- "hdr": hdr,
294
- "guidance_scale": guidance_scale,
295
- "max_frames": max_frames,
296
- "frame_interval": frame_interval,
297
- "preserve_frames": preserve_frames
 
298
  }
299
  with open(os.path.join(job_folder, "config.json"), "w") as f:
300
  json.dump(config, f)
@@ -320,7 +321,6 @@ def process_video(input_video, resolution, num_inference_steps, strength, hdr, g
320
 
321
  try:
322
  progress(0.2, desc="Processing frames...")
323
- batch_size = 8
324
  for i in tqdm(range(0, frames_to_process, batch_size), desc="Processing batches"):
325
  if abort_event.is_set():
326
  print("Job aborted. Stopping processing of new frames.")
@@ -359,7 +359,7 @@ def process_video(input_video, resolution, num_inference_steps, strength, hdr, g
359
  return None
360
 
361
  @spaces.GPU(duration=400)
362
- def gradio_process_media(input_media, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames, progress=gr.Progress()):
363
  abort_event.clear() # Clear the abort flag at the start of a new job
364
  if input_media is None:
365
  return None, "No input media provided."
@@ -385,7 +385,7 @@ def gradio_process_media(input_media, resolution, num_inference_steps, strength,
385
  video_extensions = ('.mp4', '.avi', '.mov', '.mkv')
386
  if file_path.lower().endswith(video_extensions):
387
  print("Processing video...")
388
- result = process_video(file_path, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames, progress)
389
  if result:
390
  return result, "Video processing completed successfully."
391
  else:
@@ -427,6 +427,7 @@ with gr.Blocks(css=css, theme=gr.themes.Default(primary_hue="blue")) as iface:
427
  max_frames = gr.Number(label="Max Frames to Process (leave empty for full video)", precision=0)
428
  frame_interval = gr.Slider(1, 30, 1, step=1, label="Frame Interval (process every nth frame)")
429
  preserve_frames = gr.Checkbox(label="Preserve Existing Processed Frames", value=True)
 
430
 
431
  with gr.Column(scale=1):
432
  submit_button = gr.Button("Process Media")
@@ -436,7 +437,7 @@ with gr.Blocks(css=css, theme=gr.themes.Default(primary_hue="blue")) as iface:
436
 
437
  submit_button.click(
438
  gradio_process_media,
439
- inputs=[input_media, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames],
440
  outputs=[output, status]
441
  )
442
 
 
275
  os.remove(temp_output_path)
276
 
277
  @timer_func
278
+ def process_video(input_video, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames=None, frame_interval=1, preserve_frames=False, batch_size=4, progress=gr.Progress()):
279
  abort_event.clear() # Clear the abort flag at the start of a new job
280
  print("Starting video processing...")
281
  model_manager.load_models(progress) # Ensure models are loaded
 
287
 
288
  # Save job config
289
  config = {
290
+ "resolution": resolution,
291
+ "num_inference_steps": num_inference_steps,
292
+ "strength": strength,
293
+ "hdr": hdr,
294
+ "guidance_scale": guidance_scale,
295
+ "max_frames": max_frames,
296
+ "frame_interval": frame_interval,
297
+ "preserve_frames": preserve_frames,
298
+ "batch_size": batch_size
299
  }
300
  with open(os.path.join(job_folder, "config.json"), "w") as f:
301
  json.dump(config, f)
 
321
 
322
  try:
323
  progress(0.2, desc="Processing frames...")
 
324
  for i in tqdm(range(0, frames_to_process, batch_size), desc="Processing batches"):
325
  if abort_event.is_set():
326
  print("Job aborted. Stopping processing of new frames.")
 
359
  return None
360
 
361
  @spaces.GPU(duration=400)
362
+ def gradio_process_media(input_media, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames, batch_size, progress=gr.Progress()):
363
  abort_event.clear() # Clear the abort flag at the start of a new job
364
  if input_media is None:
365
  return None, "No input media provided."
 
385
  video_extensions = ('.mp4', '.avi', '.mov', '.mkv')
386
  if file_path.lower().endswith(video_extensions):
387
  print("Processing video...")
388
+ result = process_video(file_path, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames, batch_size, progress)
389
  if result:
390
  return result, "Video processing completed successfully."
391
  else:
 
427
  max_frames = gr.Number(label="Max Frames to Process (leave empty for full video)", precision=0)
428
  frame_interval = gr.Slider(1, 30, 1, step=1, label="Frame Interval (process every nth frame)")
429
  preserve_frames = gr.Checkbox(label="Preserve Existing Processed Frames", value=True)
430
+ batch_size = gr.Slider(1, 16, 1, step=1, label="Batch Size")
431
 
432
  with gr.Column(scale=1):
433
  submit_button = gr.Button("Process Media")
 
437
 
438
  submit_button.click(
439
  gradio_process_media,
440
+ inputs=[input_media, resolution, num_inference_steps, strength, hdr, guidance_scale, max_frames, frame_interval, preserve_frames, batch_size],
441
  outputs=[output, status]
442
  )
443