Hunyuan-Avatar / app.py
rahul7star's picture
Update app.py
d491e94 verified
raw
history blame
2.03 kB
import os
import sys
import subprocess
from huggingface_hub import snapshot_download
MODEL_BASE = "./weights"
MODEL_DIR = os.path.join(MODEL_BASE, "ckpts/hunyuan-video-t2v-720p")
CHECKPOINT_FILE = os.path.join(MODEL_DIR, "transformers/mp_rank_00_model_states.pt")
def download_model():
print("⬇️ Model not found. Downloading from Hugging Face...")
os.makedirs(MODEL_DIR, exist_ok=True)
snapshot_download(
repo_id="tencent/HunyuanVideo-Avatar",
local_dir=MODEL_DIR,
local_dir_use_symlinks=False,
)
if not os.path.isfile(CHECKPOINT_FILE):
print("❌ Failed to download model checkpoint. Exiting.")
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"
]
# Start process in background
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()
# Optionally wait a few seconds for flask_audio.py to start before starting Gradio UI
import time
time.sleep(5)
gradio_proc = run_gradio_ui()
# Wait for both processes to exit if you want to block here, or just exit
# flask_proc.wait()
# gradio_proc.wait()
if __name__ == "__main__":
main()