Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ CHECKPOINT_FILES = [
|
|
| 28 |
|
| 29 |
_setup_lock = threading.Lock()
|
| 30 |
|
|
|
|
| 31 |
def run(cmd, cwd=None, extra_env=None):
|
| 32 |
env = os.environ.copy()
|
| 33 |
if extra_env:
|
|
@@ -43,15 +44,19 @@ def run(cmd, cwd=None, extra_env=None):
|
|
| 43 |
env=env,
|
| 44 |
)
|
| 45 |
if p.returncode != 0:
|
| 46 |
-
raise RuntimeError(
|
|
|
|
|
|
|
| 47 |
return p.stdout
|
| 48 |
|
|
|
|
| 49 |
def download_file(url: str, dest: Path):
|
| 50 |
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 51 |
if dest.exists() and dest.stat().st_size > 0:
|
| 52 |
return
|
| 53 |
run(["bash", "-lc", f'curl -L -C - --retry 5 --retry-delay 2 -o "{dest}" "{url}"'])
|
| 54 |
|
|
|
|
| 55 |
def ensure_checkpoints():
|
| 56 |
ckpt_dir = REPO_DIR / "checkpoints"
|
| 57 |
ckpt_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -59,12 +64,14 @@ def ensure_checkpoints():
|
|
| 59 |
for fname in CHECKPOINT_FILES:
|
| 60 |
download_file(f"{HF_BASE}/{fname}", ckpt_dir / fname)
|
| 61 |
|
|
|
|
| 62 |
bfm_zip = ckpt_dir / "BFM.zip"
|
| 63 |
bfm_dir = ckpt_dir / "BFM"
|
| 64 |
if not bfm_dir.exists():
|
| 65 |
bfm_dir.mkdir(parents=True, exist_ok=True)
|
| 66 |
run(["unzip", "-q", str(bfm_zip), "-d", str(bfm_dir)])
|
| 67 |
|
|
|
|
| 68 |
def setup():
|
| 69 |
with _setup_lock:
|
| 70 |
if SETUP_FLAG.exists() and REPO_DIR.exists():
|
|
@@ -73,8 +80,11 @@ def setup():
|
|
| 73 |
print("Setting up Video-Retalking...")
|
| 74 |
|
| 75 |
if not REPO_DIR.exists():
|
| 76 |
-
run(
|
|
|
|
|
|
|
| 77 |
|
|
|
|
| 78 |
try:
|
| 79 |
run(["git", "lfs", "pull"], cwd=REPO_DIR)
|
| 80 |
except Exception:
|
|
@@ -85,6 +95,7 @@ def setup():
|
|
| 85 |
SETUP_FLAG.touch()
|
| 86 |
print("✅ Setup complete!")
|
| 87 |
|
|
|
|
| 88 |
def generate(image_path, audio_path):
|
| 89 |
if not image_path or not audio_path:
|
| 90 |
return None, "❌ Upload both image and audio!"
|
|
@@ -99,7 +110,6 @@ def generate(image_path, audio_path):
|
|
| 99 |
if out_path.exists():
|
| 100 |
out_path.unlink()
|
| 101 |
|
| 102 |
-
# Fix OMP warning by forcing a valid integer value
|
| 103 |
safe_env = {
|
| 104 |
"OMP_NUM_THREADS": "1",
|
| 105 |
"MKL_NUM_THREADS": "1",
|
|
@@ -110,9 +120,12 @@ def generate(image_path, audio_path):
|
|
| 110 |
cmd = [
|
| 111 |
"python",
|
| 112 |
"inference.py",
|
| 113 |
-
"--face",
|
| 114 |
-
|
| 115 |
-
"--
|
|
|
|
|
|
|
|
|
|
| 116 |
]
|
| 117 |
run(cmd, cwd=REPO_DIR, extra_env=safe_env)
|
| 118 |
|
|
@@ -123,6 +136,7 @@ def generate(image_path, audio_path):
|
|
| 123 |
except Exception as e:
|
| 124 |
return None, f"❌ Error: {e}"
|
| 125 |
|
|
|
|
| 126 |
demo = gr.Interface(
|
| 127 |
fn=generate,
|
| 128 |
inputs=[
|
|
@@ -131,7 +145,7 @@ demo = gr.Interface(
|
|
| 131 |
],
|
| 132 |
outputs=[
|
| 133 |
gr.Video(label="📹 Generated Video"),
|
| 134 |
-
gr.Textbox(label="Status", lines=
|
| 135 |
],
|
| 136 |
title="🎬 Video-Retalking Lip Sync",
|
| 137 |
description="Upload a face image and audio to generate a lip-synced video.",
|
|
|
|
| 28 |
|
| 29 |
_setup_lock = threading.Lock()
|
| 30 |
|
| 31 |
+
|
| 32 |
def run(cmd, cwd=None, extra_env=None):
|
| 33 |
env = os.environ.copy()
|
| 34 |
if extra_env:
|
|
|
|
| 44 |
env=env,
|
| 45 |
)
|
| 46 |
if p.returncode != 0:
|
| 47 |
+
raise RuntimeError(
|
| 48 |
+
f"Command failed ({p.returncode}): {' '.join(cmd)}\n\n{p.stdout}"
|
| 49 |
+
)
|
| 50 |
return p.stdout
|
| 51 |
|
| 52 |
+
|
| 53 |
def download_file(url: str, dest: Path):
|
| 54 |
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 55 |
if dest.exists() and dest.stat().st_size > 0:
|
| 56 |
return
|
| 57 |
run(["bash", "-lc", f'curl -L -C - --retry 5 --retry-delay 2 -o "{dest}" "{url}"'])
|
| 58 |
|
| 59 |
+
|
| 60 |
def ensure_checkpoints():
|
| 61 |
ckpt_dir = REPO_DIR / "checkpoints"
|
| 62 |
ckpt_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 64 |
for fname in CHECKPOINT_FILES:
|
| 65 |
download_file(f"{HF_BASE}/{fname}", ckpt_dir / fname)
|
| 66 |
|
| 67 |
+
# Unzip BFM.zip -> checkpoints/BFM/
|
| 68 |
bfm_zip = ckpt_dir / "BFM.zip"
|
| 69 |
bfm_dir = ckpt_dir / "BFM"
|
| 70 |
if not bfm_dir.exists():
|
| 71 |
bfm_dir.mkdir(parents=True, exist_ok=True)
|
| 72 |
run(["unzip", "-q", str(bfm_zip), "-d", str(bfm_dir)])
|
| 73 |
|
| 74 |
+
|
| 75 |
def setup():
|
| 76 |
with _setup_lock:
|
| 77 |
if SETUP_FLAG.exists() and REPO_DIR.exists():
|
|
|
|
| 80 |
print("Setting up Video-Retalking...")
|
| 81 |
|
| 82 |
if not REPO_DIR.exists():
|
| 83 |
+
run(
|
| 84 |
+
["git", "clone", "https://github.com/OpenTalker/video-retalking.git", str(REPO_DIR)]
|
| 85 |
+
)
|
| 86 |
|
| 87 |
+
# Best effort
|
| 88 |
try:
|
| 89 |
run(["git", "lfs", "pull"], cwd=REPO_DIR)
|
| 90 |
except Exception:
|
|
|
|
| 95 |
SETUP_FLAG.touch()
|
| 96 |
print("✅ Setup complete!")
|
| 97 |
|
| 98 |
+
|
| 99 |
def generate(image_path, audio_path):
|
| 100 |
if not image_path or not audio_path:
|
| 101 |
return None, "❌ Upload both image and audio!"
|
|
|
|
| 110 |
if out_path.exists():
|
| 111 |
out_path.unlink()
|
| 112 |
|
|
|
|
| 113 |
safe_env = {
|
| 114 |
"OMP_NUM_THREADS": "1",
|
| 115 |
"MKL_NUM_THREADS": "1",
|
|
|
|
| 120 |
cmd = [
|
| 121 |
"python",
|
| 122 |
"inference.py",
|
| 123 |
+
"--face",
|
| 124 |
+
str(image_path),
|
| 125 |
+
"--audio",
|
| 126 |
+
str(audio_path),
|
| 127 |
+
"--outfile",
|
| 128 |
+
str(out_path),
|
| 129 |
]
|
| 130 |
run(cmd, cwd=REPO_DIR, extra_env=safe_env)
|
| 131 |
|
|
|
|
| 136 |
except Exception as e:
|
| 137 |
return None, f"❌ Error: {e}"
|
| 138 |
|
| 139 |
+
|
| 140 |
demo = gr.Interface(
|
| 141 |
fn=generate,
|
| 142 |
inputs=[
|
|
|
|
| 145 |
],
|
| 146 |
outputs=[
|
| 147 |
gr.Video(label="📹 Generated Video"),
|
| 148 |
+
gr.Textbox(label="Status", lines=6),
|
| 149 |
],
|
| 150 |
title="🎬 Video-Retalking Lip Sync",
|
| 151 |
description="Upload a face image and audio to generate a lip-synced video.",
|