V commited on
Commit
f3aeb0d
·
verified ·
1 Parent(s): 9df4fca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -3
app.py CHANGED
@@ -467,7 +467,57 @@ def generate_video(
467
 
468
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
469
 
470
- return video_path, current_seed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
  with gr.Blocks() as demo:
473
  gr.Markdown("# Wan22 AOT")
@@ -488,7 +538,8 @@ with gr.Blocks() as demo:
488
 
489
  generate_button = gr.Button("Generate Video", variant="primary")
490
  with gr.Column():
491
- video_output = gr.Video(label="Generated Video", autoplay=True, interactive=False)
 
492
 
493
  #upload_image_and_prompt(input_image_component, prompt_input)
494
  ui_inputs = [
@@ -497,7 +548,14 @@ with gr.Blocks() as demo:
497
  guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox
498
  ]
499
 
500
- generate_button.click(fn=generate_video_with_upload, inputs=ui_inputs, outputs=[video_output, seed_input])
 
 
 
 
 
 
 
501
 
502
  if __name__ == "__main__":
503
  demo.queue().launch(mcp_server=True)
 
467
 
468
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
469
 
470
+ if check_ffmpeg():
471
+ try:
472
+ # Создаем временный файл для видео с звуком
473
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as audio_tmpfile:
474
+ video_with_audio_path = audio_tmpfile.name
475
+
476
+ # Команда ffmpeg для добавления тихого аудио
477
+ cmd = [
478
+ 'ffmpeg',
479
+ '-f', 'lavfi',
480
+ '-i', 'anullsrc=channel_layout=stereo:sample_rate=44100',
481
+ '-i', video_path,
482
+ '-c:v', 'copy',
483
+ '-c:a', 'aac',
484
+ '-shortest',
485
+ '-y',
486
+ video_with_audio_path
487
+ ]
488
+
489
+ # Запускаем ffmpeg
490
+ subprocess.run(cmd, capture_output=True, check=True)
491
+
492
+ # Создаем временный файл для заблюренного видео
493
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as blur_tmpfile:
494
+ blurred_video_path = blur_tmpfile.name
495
+
496
+ # Команда ffmpeg для создания гауссова размытия
497
+ cmd_blur = [
498
+ 'ffmpeg',
499
+ '-i', video_with_audio_path, # Используем видео с аудио как источник
500
+ '-vf', 'gblur=sigma=25', # Гауссово размытие с sigma=5
501
+ '-c:a', 'copy', # Копируем аудио без изменений
502
+ '-y',
503
+ blurred_video_path
504
+ ]
505
+
506
+ # Запускаем ffmpeg для создания блюра
507
+ subprocess.run(cmd_blur, capture_output=True, check=True)
508
+
509
+ # Удаляем исходный файл без звука
510
+ os.unlink(video_path)
511
+
512
+ return video_with_audio_path, blurred_video_path, current_seed
513
+
514
+ except Exception as e:
515
+ print(f"Error adding audio: {e}")
516
+ # В случае ошибки возвращаем видео без звука
517
+ return video_path, video_path, current_seed
518
+ else:
519
+ print("FFmpeg not available, returning video without audio")
520
+ return video_path, video_path, current_seed
521
 
522
  with gr.Blocks() as demo:
523
  gr.Markdown("# Wan22 AOT")
 
538
 
539
  generate_button = gr.Button("Generate Video", variant="primary")
540
  with gr.Column():
541
+ video_output_1 = gr.Video(label="Generated Video", autoplay=True, interactive=False)
542
+ video_output_2 = gr.Video(label="Generated Video", autoplay=True, interactive=False)
543
 
544
  #upload_image_and_prompt(input_image_component, prompt_input)
545
  ui_inputs = [
 
548
  guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox
549
  ]
550
 
551
+ generate_button.click(fn=generate_video_with_upload, inputs=ui_inputs, outputs=[video_output_1, video_output_2, seed_input])
552
+
553
+ def check_ffmpeg():
554
+ try:
555
+ subprocess.run(['ffmpeg', '-version'], capture_output=True, check=True)
556
+ return True
557
+ except (subprocess.CalledProcessError, FileNotFoundError):
558
+ return False
559
 
560
  if __name__ == "__main__":
561
  demo.queue().launch(mcp_server=True)