Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
import spaces
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
# --- 1. BOOTSTRAP ENVIRONMENT ---
|
| 9 |
+
def setup_repos():
|
| 10 |
+
if not os.path.exists("/app/SadTalker"):
|
| 11 |
+
print("📥 Cloning Repositories...")
|
| 12 |
+
subprocess.run(["git", "clone", "https://github.com/OpenTalker/SadTalker.git", "/app/SadTalker"])
|
| 13 |
+
subprocess.run(["git", "clone", "https://github.com/Rudrabha/Wav2Lip.git", "/app/Wav2Lip"])
|
| 14 |
+
# Fix BasicSR compatibility
|
| 15 |
+
subprocess.run(["find", "/usr/local/lib/python3.10/site-packages/basicsr", "-name", "degradations.py", "-exec", "sed", "-i", "s/functional_tensor/functional/g", "{}", "+"])
|
| 16 |
+
|
| 17 |
+
setup_repos()
|
| 18 |
+
|
| 19 |
+
# --- 2. THE GPU-ACCELERATED CORE ---
|
| 20 |
+
@spaces.GPU(duration=120) # Grants H200 access for 2 minutes per click
|
| 21 |
+
def generate(image, audio):
|
| 22 |
+
# Setup paths
|
| 23 |
+
workspace = Path("/tmp/visor_workspace")
|
| 24 |
+
workspace.mkdir(parents=True, exist_ok=True)
|
| 25 |
+
|
| 26 |
+
img_path = workspace / "input.jpg"
|
| 27 |
+
aud_path = workspace / "input.mp3"
|
| 28 |
+
|
| 29 |
+
# Gradio provides file paths directly
|
| 30 |
+
shutil.copy(image, img_path)
|
| 31 |
+
shutil.copy(audio, aud_path)
|
| 32 |
+
|
| 33 |
+
# Note: On HF Spaces, you should use their 'checkpoints' or
|
| 34 |
+
# use 'gdown' to pull your weights into /app/SadTalker/checkpoints
|
| 35 |
+
# For testing, SadTalker will auto-download if folder is empty.
|
| 36 |
+
|
| 37 |
+
print("🎬 Running Animation...")
|
| 38 |
+
subprocess.run([
|
| 39 |
+
"python", "/app/SadTalker/inference.py",
|
| 40 |
+
"--driven_audio", str(aud_path),
|
| 41 |
+
"--source_image", str(img_path),
|
| 42 |
+
"--result_dir", "/tmp/results",
|
| 43 |
+
"--still", "--preprocess", "full"
|
| 44 |
+
], env={**os.environ, "PYTHONPATH": "/app/SadTalker"})
|
| 45 |
+
|
| 46 |
+
# Return the first mp4 found
|
| 47 |
+
result_video = list(Path("/tmp/results").glob("**/*.mp4"))
|
| 48 |
+
return result_video[0] if result_video else None
|
| 49 |
+
|
| 50 |
+
# --- 3. GRADIO INTERFACE (The Frontend) ---
|
| 51 |
+
with gr.Blocks(title="VisorFlow Core") as demo:
|
| 52 |
+
gr.Markdown("# 🛡️ VisorFlow Core: ZeroGPU Edition")
|
| 53 |
+
with gr.Row():
|
| 54 |
+
with gr.Column():
|
| 55 |
+
input_img = gr.Image(type="filepath", label="Source Image")
|
| 56 |
+
input_aud = gr.Audio(type="filepath", label="Driven Audio")
|
| 57 |
+
run_btn = gr.Button("Execute Phase 3", variant="primary")
|
| 58 |
+
with gr.Column():
|
| 59 |
+
output_video = gr.Video(label="Generated Intelligence")
|
| 60 |
+
|
| 61 |
+
run_btn.click(fn=generate, inputs=[input_img, input_aud], outputs=[output_video])
|
| 62 |
+
|
| 63 |
+
demo.launch()
|