banao-tech commited on
Commit
3e80b31
·
verified ·
1 Parent(s): dc91850

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -67
app.py CHANGED
@@ -1,77 +1,42 @@
1
- import os
2
  import gradio as gr
3
  import subprocess
4
  from pathlib import Path
5
- import shutil
6
-
7
- # Simple setup
8
- ROOT = Path("/tmp/musehub")
9
- ROOT.mkdir(exist_ok=True)
10
 
11
- def generate_lipsync(image_path, audio_path):
12
- """Generate lip-synced video using simple ffmpeg + ML approach"""
 
 
13
  try:
14
- if not image_path or not audio_path:
15
- return None, "❌ Please upload both image and audio"
16
-
17
- output = ROOT / "output.mp4"
18
-
19
- # Method 1: Use video-retalking (simpler and works on T4)
20
- cmd = [
21
- "python", "inference.py",
22
- "--face", image_path,
23
- "--audio", audio_path,
24
- "--outfile", str(output)
25
- ]
26
-
27
- subprocess.run(cmd, check=True, cwd="/app/video-retalking")
28
-
29
- if output.exists():
30
- return str(output), "✅ Video generated!"
31
- return None, "❌ Generation failed"
32
 
 
 
33
  except Exception as e:
34
- return None, f"❌ Error: {str(e)}"
35
 
36
- def setup_model():
37
- """Download and setup video-retalking"""
38
- repo_dir = Path("/app/video-retalking")
39
- if repo_dir.exists():
40
- return True
41
-
42
- try:
43
- # Clone repo
44
- subprocess.run([
45
- "git", "clone",
46
- "https://github.com/OpenTalker/video-retalking.git",
47
- str(repo_dir)
48
- ], check=True)
49
-
50
- # Download checkpoints
51
- subprocess.run([
52
- "bash", "scripts/download_models.sh"
53
- ], cwd=repo_dir, check=True)
54
-
55
- return True
56
- except:
57
- return False
58
 
59
- # Gradio UI
60
- with gr.Blocks(title="AI Lip Sync") as demo:
61
- gr.Markdown("# 🎤 AI Lip Sync Generator\nUpload a face image and audio to create lip-synced video")
62
-
63
- with gr.Row():
64
- with gr.Column():
65
- image = gr.Image(type="filepath", label="Face Image")
66
- audio = gr.Audio(type="filepath", label="Audio File")
67
- btn = gr.Button("🚀 Generate", variant="primary")
68
-
69
- with gr.Column():
70
- video = gr.Video(label="Result")
71
- status = gr.Textbox(label="Status")
72
-
73
- btn.click(generate_lipsync, [image, audio], [video, status])
74
 
75
- if __name__ == "__main__":
76
- setup_model()
77
- demo.launch()
 
 
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()