Hunyuan-Avatar / app.py
rahul7star's picture
Update app.py
093967b verified
raw
history blame
2.06 kB
import os
import sys
import subprocess
import time
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
BASE_DIR = "HunyuanVideo-Avatar"
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
CHECKPOINT_FILE = os.path.join(WEIGHTS_DIR, "transformers/mp_rank_00_model_states.pt") # Adjust if needed
def download_model():
print("⬇️ Model not found. Downloading with huggingface-cli inside HunyuanVideo-Avatar/weights...")
os.makedirs(WEIGHTS_DIR, exist_ok=True)
# Run huggingface-cli download inside WEIGHTS_DIR
cmd = ["huggingface-cli", "download", MODEL_REPO, "--local-dir", "./"]
proc = subprocess.run(cmd, cwd=WEIGHTS_DIR)
if proc.returncode != 0:
print("❌ huggingface-cli download failed.")
sys.exit(1)
# Check if checkpoint file exists now
if not os.path.isfile(CHECKPOINT_FILE):
print(f"❌ Checkpoint file not found at {CHECKPOINT_FILE} after download.")
sys.exit(1)
print("βœ… Model downloaded successfully.")
def run_flask_audio():
print("πŸš€ Starting flask_audio.py...")
cmd = [
"torchrun",
"--nnodes=1",
"--nproc_per_node=8",
"--master_port=29605",
"hymm_gradio/flask_audio.py",
"--input", "assets/test.csv",
"--ckpt", CHECKPOINT_FILE,
"--sample-n-frames", "129",
"--seed", "128",
"--image-size", "704",
"--cfg-scale", "7.5",
"--infer-steps", "50",
"--use-deepcache", "1",
"--flow-shift-eval-video", "5.0"
]
proc = subprocess.Popen(cmd)
return proc
def run_gradio_ui():
print("🟒 Starting gradio_audio.py UI...")
cmd = ["python3", "hymm_gradio/gradio_audio.py"]
proc = subprocess.Popen(cmd)
return proc
def main():
if os.path.isfile(CHECKPOINT_FILE):
print("βœ… Model checkpoint already exists. Skipping download.")
else:
download_model()
flask_proc = run_flask_audio()
time.sleep(5) # Wait for flask_audio.py to spin up
gradio_proc = run_gradio_ui()
if __name__ == "__main__":
main()