Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
| 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()
|