pratikshahp commited on
Commit
6f7450f
·
verified ·
1 Parent(s): 34eb10a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -29
app.py CHANGED
@@ -1,40 +1,27 @@
1
  import gradio as gr
2
- import subprocess
3
- import os
4
 
5
- # Ensure checkpoints folder exists
6
- assert os.path.exists("Wav2Lip/checkpoints/wav2lip.pth"), "checkpoint not found"
7
 
8
- def generate(script, mic_audio, webcam_video):
9
- # Save script to temp for TTS (if needed)
10
- with open("script.txt", "w") as f:
11
- f.write(script)
12
-
13
- # Assume mic_audio & webcam_video are files
14
- audio_path = mic_audio.name
15
- video_path = webcam_video.name
16
-
17
- # Run Wav2Lip with your existing command
18
- cmd = [
19
  "python", "inference.py",
20
  "--checkpoint_path", "checkpoints/wav2lip.pth",
21
  "--face", video_path,
22
- "--audio", audio_path,
23
- "--outfile", "results/output.mp4"
24
- ]
25
- subprocess.call(cmd)
26
-
27
- return "results/output.mp4"
28
 
29
- # Build Gradio interface
30
  with gr.Blocks() as demo:
31
- gr.Markdown("## 🎙️ Wav2Lip Lip-Sync Video Generator")
32
- script_input = gr.Textbox(lines=4, placeholder="Paste your script here")
33
  mic = gr.Audio(sources=["microphone"], type="filepath", label="Record Audio")
34
- webcam = gr.Video(sources=["webcam"], label="Record Video")
35
- generate_btn = gr.Button("Generate Video")
36
- output_video = gr.Video(label="Generated Video")
37
 
38
- generate_btn.click(fn=generate, inputs=[script_input, mic, webcam], outputs=output_video)
39
 
40
- demo.launch()
 
1
  import gradio as gr
2
+ import subprocess, os
 
3
 
4
+ assert os.path.exists("checkpoints/wav2lip.pth")
 
5
 
6
+ def generate(mic_path: str, video_path: str):
7
+ output_path = "results/output.mp4"
8
+ os.makedirs("results", exist_ok=True)
9
+ subprocess.call([
 
 
 
 
 
 
 
10
  "python", "inference.py",
11
  "--checkpoint_path", "checkpoints/wav2lip.pth",
12
  "--face", video_path,
13
+ "--audio", mic_path,
14
+ "--outfile", output_path
15
+ ])
16
+ return output_path
 
 
17
 
 
18
  with gr.Blocks() as demo:
19
+ gr.Markdown("## 🎬 AI LipSync Video Recorder")
 
20
  mic = gr.Audio(sources=["microphone"], type="filepath", label="Record Audio")
21
+ webcam = gr.Video(sources=["webcam"], type="filepath", label="Record Video")
22
+ btn = gr.Button("Generate Video")
23
+ out = gr.Video(label="Generated Video")
24
 
25
+ btn.click(generate, inputs=[mic, webcam], outputs=out)
26
 
27
+ demo.launch(share=True)