banao-tech commited on
Commit
94c8c66
Ā·
verified Ā·
1 Parent(s): e86ec4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -33
app.py CHANGED
@@ -1,42 +1,62 @@
1
  import gradio as gr
 
2
  import subprocess
3
- from pathlib import Path
4
  import os
 
5
 
6
- def generate(image, audio):
7
- if not image or not audio:
8
- return None, "Upload both files"
9
-
 
 
 
10
  try:
11
- # Use makeittalk - simple and reliable
12
- result = subprocess.run([
13
- "python", "main_end2end.py",
14
- "--jpg", image,
15
- "--audio", audio,
16
- "--config", "config/simple.yaml"
17
- ], capture_output=True, cwd="/app/makeittalk")
18
 
19
- output = Path("/app/makeittalk/examples/output.mp4")
20
- return str(output) if output.exists() else None, "Done!"
 
 
 
 
 
 
 
 
 
 
 
 
21
  except Exception as e:
22
- return None, str(e)
23
-
24
- demo = gr.Interface(
25
- fn=generate,
26
- inputs=[
27
- gr.Image(type="filepath", label="Face"),
28
- gr.Audio(type="filepath", label="Audio")
29
- ],
30
- outputs=[
31
- gr.Video(label="Result"),
32
- gr.Textbox(label="Status")
33
- ],
34
- title="AI Lip Sync"
35
- )
36
 
37
- # Setup on start
38
- if not Path("/app/makeittalk").exists():
39
- subprocess.run(["git", "clone", "https://github.com/yzhou359/MakeItTalk.git", "/app/makeittalk"])
40
- subprocess.run(["bash", "quick_demo.sh"], cwd="/app/makeittalk")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- demo.launch()
 
 
1
  import gradio as gr
2
+ import torch
3
  import subprocess
 
4
  import os
5
+ from pathlib import Path
6
 
7
+ def setup():
8
+ """One-time setup"""
9
+ if not Path("DiffSynth-Studio").exists():
10
+ subprocess.run("git clone https://github.com/modelscope/DiffSynth-Studio.git", shell=True)
11
+ subprocess.run("pip install -e ./DiffSynth-Studio", shell=True)
12
+
13
+ def generate_video(image, audio):
14
  try:
15
+ if not image or not audio:
16
+ return None, "Please upload both image and audio!"
17
+
18
+ setup()
19
+
20
+ # Run inference
21
+ output_path = "output.mp4"
22
 
23
+ cmd = f"""
24
+ cd DiffSynth-Studio && python examples/video_generation/musetalk.py \
25
+ --image_path ../{image} \
26
+ --audio_path ../{audio} \
27
+ --output_path ../{output_path}
28
+ """
29
+
30
+ result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
31
+
32
+ if Path(output_path).exists():
33
+ return output_path, "āœ… Video generated successfully!"
34
+ else:
35
+ return None, f"āŒ Failed: {result.stderr}"
36
+
37
  except Exception as e:
38
+ return None, f"āŒ Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ # Gradio Interface
41
+ with gr.Blocks(title="AI Lip Sync") as app:
42
+ gr.Markdown("# šŸŽ¤ AI Lip Sync Generator")
43
+ gr.Markdown("Upload a face image and audio to generate lip-synced video")
44
+
45
+ with gr.Row():
46
+ with gr.Column():
47
+ image_input = gr.Image(type="filepath", label="šŸ“· Face Image")
48
+ audio_input = gr.Audio(type="filepath", label="šŸŽµ Audio File")
49
+ generate_btn = gr.Button("šŸš€ Generate Video", variant="primary")
50
+
51
+ with gr.Column():
52
+ video_output = gr.Video(label="šŸ“¹ Generated Video")
53
+ status_output = gr.Textbox(label="Status", lines=2)
54
+
55
+ generate_btn.click(
56
+ fn=generate_video,
57
+ inputs=[image_input, audio_input],
58
+ outputs=[video_output, status_output]
59
+ )
60
 
61
+ if __name__ == "__main__":
62
+ app.launch()