| import os
|
| import shutil
|
| import subprocess
|
| import spaces
|
| import gradio as gr
|
| from pathlib import Path
|
|
|
|
|
| def setup_repos():
|
| if not os.path.exists("/app/SadTalker"):
|
| print("📥 Cloning Repositories...")
|
| subprocess.run(["git", "clone", "https://github.com/OpenTalker/SadTalker.git", "/app/SadTalker"])
|
| subprocess.run(["git", "clone", "https://github.com/Rudrabha/Wav2Lip.git", "/app/Wav2Lip"])
|
|
|
| subprocess.run(["find", "/usr/local/lib/python3.10/site-packages/basicsr", "-name", "degradations.py", "-exec", "sed", "-i", "s/functional_tensor/functional/g", "{}", "+"])
|
|
|
| setup_repos()
|
|
|
|
|
| @spaces.GPU(duration=120)
|
| def generate(image, audio):
|
|
|
| workspace = Path("/tmp/visor_workspace")
|
| workspace.mkdir(parents=True, exist_ok=True)
|
|
|
| img_path = workspace / "input.jpg"
|
| aud_path = workspace / "input.mp3"
|
|
|
|
|
| shutil.copy(image, img_path)
|
| shutil.copy(audio, aud_path)
|
|
|
|
|
|
|
|
|
|
|
| print("🎬 Running Animation...")
|
| subprocess.run([
|
| "python", "/app/SadTalker/inference.py",
|
| "--driven_audio", str(aud_path),
|
| "--source_image", str(img_path),
|
| "--result_dir", "/tmp/results",
|
| "--still", "--preprocess", "full"
|
| ], env={**os.environ, "PYTHONPATH": "/app/SadTalker"})
|
|
|
|
|
| result_video = list(Path("/tmp/results").glob("**/*.mp4"))
|
| return result_video[0] if result_video else None
|
|
|
|
|
| with gr.Blocks(title="VisorFlow Core") as demo:
|
| gr.Markdown("# 🛡️ VisorFlow Core: ZeroGPU Edition")
|
| with gr.Row():
|
| with gr.Column():
|
| input_img = gr.Image(type="filepath", label="Source Image")
|
| input_aud = gr.Audio(type="filepath", label="Driven Audio")
|
| run_btn = gr.Button("Execute Phase 3", variant="primary")
|
| with gr.Column():
|
| output_video = gr.Video(label="Generated Intelligence")
|
|
|
| run_btn.click(fn=generate, inputs=[input_img, input_aud], outputs=[output_video])
|
|
|
| demo.launch() |