Spaces:
Paused
Paused
Update app.py
Browse files27 unmodified lines2829303132339 unmodified lines4344454647484950515253545556571 unmodified line5960616263646566676869702 unmodified lines73747576777879804 unmodified lines8586878889908 unmodified lines991001011021031041054 unmodified lines1101111121131141151161171184 unmodified lines1231241251261271282 unmodified lines13113213313413513613727 unmodified lines_setup_lock = threading.Lock()def run(cmd, cwd=None, extra_env=None):env = os.environ.copy()if extra_env:9 unmodified linesenv=env,)if p.returncode != 0:raise RuntimeError(f"Command failed ({p.returncode}): {' '.join(cmd)}\n\n{p.stdout}")return p.stdoutdef download_file(url: str, dest: Path):dest.parent.mkdir(parents=True, exist_ok=True)if dest.exists() and dest.stat().st_size > 0:returnrun(["bash", "-lc", f'curl -L -C - --retry 5 --retry-delay 2 -o "{dest}" "{url}"'])def ensure_checkpoints():ckpt_dir = REPO_DIR / "checkpoints"ckpt_dir.mkdir(parents=True, exist_ok=True)1 unmodified linefor fname in CHECKPOINT_FILES:download_file(f"{HF_BASE}/{fname}", ckpt_dir / fname)bfm_zip = ckpt_dir / "BFM.zip"bfm_dir = ckpt_dir / "BFM"if not bfm_dir.exists():bfm_dir.mkdir(parents=True, exist_ok=True)run(["unzip", "-q", str(bfm_zip), "-d", str(bfm_dir)])def setup():with _setup_lock:if SETUP_FLAG.exists() and REPO_DIR.exists():2 unmodified linesprint("Setting up Video-Retalking...")if not REPO_DIR.exists():run(["git", "clone", "https://github.com/OpenTalker/video-retalking.git", str(REPO_DIR)])try:run(["git", "lfs", "pull"], cwd=REPO_DIR)except Exception:4 unmodified linesSETUP_FLAG.touch()print("β Setup complete!")def generate(image_path, audio_path):if not image_path or not audio_path:return None, "β Upload both image and audio!"8 unmodified linesif out_path.exists():out_path.unlink()# Fix OMP warning by forcing a valid integer valuesafe_env = {"OMP_NUM_THREADS": "1","MKL_NUM_THREADS": "1",4 unmodified linescmd = ["python","inference.py","--face", str(image_path),"--audio", str(audio_path),"--outfile", str(out_path),]run(cmd, cwd=REPO_DIR, extra_env=safe_env)4 unmodified linesexcept Exception as e:return None, f"β Error: {e}"demo = gr.Interface(fn=generate,inputs=[2 unmodified lines],outputs=[gr.Video(label="πΉ Generated Video"),gr.Textbox(label="Status", lines=5),],title="π¬ Video-Retalking Lip Sync",description="Upload a face image and audio to generate a lip-synced video.",27 unmodified lines282930313233349 unmodified lines444546474849505152535455565758596061621 unmodified line64656667686970717273747576772 unmodified lines80818283848586878889904 unmodified lines95969798991001018 unmodified lines1101111121131141154 unmodified lines1201211221231241251261271281291301314 unmodified lines1361371381391401411422 unmodified lines14514614714814915015127 unmodified lines_setup_lock = threading.Lock()def run(cmd, cwd=None, extra_env=None):env = os.environ.copy()if extra_env:9 unmodified linesenv=env,)if p.returncode != 0:raise RuntimeError(f"Command failed ({p.returncode}): {' '.join(cmd)}\n\n{p.stdout}")return p.stdoutdef download_file(url: str, dest: Path):dest.parent.mkdir(parents=True, exist_ok=True)if dest.exists() and dest.stat().st_size > 0:returnrun(["bash", "-lc", f'curl -L -C - --retry 5 --retry-delay 2 -o "{dest}" "{url}"'])def ensure_checkpoints():ckpt_dir = REPO_DIR / "checkpoints"ckpt_dir.mkdir(parents=True, exist_ok=True)1 unmodified linefor fname in CHECKPOINT_FILES:download_file(f"{HF_BASE}/{fname}", ckpt_dir / fname)# Unzip BFM.zip -> checkpoints/BFM/bfm_zip = ckpt_dir / "BFM.zip"bfm_dir = ckpt_dir / "BFM"if not bfm_dir.exists():bfm_dir.mkdir(parents=True, exist_ok=True)run(["unzip", "-q", str(bfm_zip), "-d", str(bfm_dir)])def setup():with _setup_lock:if SETUP_FLAG.exists() and REPO_DIR.exists():2 unmodified linesprint("Setting up Video-Retalking...")if not REPO_DIR.exists():run(["git", "clone", "https://github.com/OpenTalker/video-retalking.git", str(REPO_DIR)])# Best efforttry:run(["git", "lfs", "pull"], cwd=REPO_DIR)except Exception:4 unmodified linesSETUP_FLAG.touch()print("β Setup complete!")def generate(image_path, audio_path):if not image_path or not audio_path:return None, "β Upload both image and audio!"8 unmodified linesif out_path.exists():out_path.unlink()safe_env = {"OMP_NUM_THREADS": "1","MKL_NUM_THREADS": "1",4 unmodified linescmd = ["python","inference.py","--face",str(image_path),"--audio",str(audio_path),"--outfile",str(out_path),]run(cmd, cwd=REPO_DIR, extra_env=safe_env)4 unmodified linesexcept Exception as e:return None, f"β Error: {e}"demo = gr.Interface(fn=generate,inputs=[2 unmodified lines],outputs=[gr.Video(label="πΉ Generated Video"),gr.Textbox(label="Status", lines=6),],title="π¬ Video-Retalking Lip Sync",description="Upload a face image and audio to generate a lip-synced video.",
app.py+21-7