Spaces:
Paused
Paused
import os | |
import sys | |
import subprocess | |
import time | |
from huggingface_hub import snapshot_download | |
MODEL_REPO = "tencent/HunyuanVideo-Avatar" | |
BASE_DIR = os.getcwd() | |
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights") | |
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor") | |
# Specific checkpoint to use in the poor sampling run | |
CHECKPOINT_FILE = os.path.join( | |
WEIGHTS_DIR, | |
"ckpts", | |
"hunyuan-video-t2v-720p", | |
"transformers", | |
"mp_rank_00_model_states.pt" | |
) | |
CHECKPOINT_FP8_FILE = os.path.join( | |
WEIGHTS_DIR, | |
"ckpts", | |
"hunyuan-video-t2v-720p", | |
"transformers", | |
"mp_rank_00_model_states_fp8.pt" | |
) | |
def download_model(): | |
print("β¬οΈ Model not found. Downloading with snapshot_download into weights directory...") | |
os.makedirs(WEIGHTS_DIR, exist_ok=True) | |
snapshot_download( | |
repo_id=MODEL_REPO, | |
local_dir=WEIGHTS_DIR, | |
local_dir_use_symlinks=False | |
) | |
if not os.path.isfile(CHECKPOINT_FILE): | |
print(f"β Checkpoint file not found at {CHECKPOINT_FILE} after download.") | |
sys.exit(1) | |
if not os.path.isfile(CHECKPOINT_FP8_FILE): | |
print(f"β FP8 checkpoint file not found at {CHECKPOINT_FP8_FILE}. Cannot proceed with sample_gpu_poor.py.") | |
sys.exit(1) | |
print("β Model downloaded successfully.") | |
def run_sample_gpu_poor(): | |
print("π¬ Running sample_gpu_poor.py...") | |
cmd = [ | |
"python3", "hymm_sp/sample_gpu_poor.py", | |
"--input", "assets/test.csv", | |
"--ckpt", CHECKPOINT_FP8_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", | |
"--save-path", OUTPUT_BASEPATH, | |
"--use-fp8", | |
"--cpu-offload", | |
"--infer-min" | |
] | |
env = os.environ.copy() | |
env["PYTHONPATH"] = "./" | |
env["MODEL_BASE"] = WEIGHTS_DIR | |
env["CPU_OFFLOAD"] = "1" | |
env["CUDA_VISIBLE_DEVICES"] = "0" | |
proc = subprocess.run(cmd, env=env) | |
if proc.returncode != 0: | |
print("β sample_gpu_poor.py failed.") | |
sys.exit(1) | |
print("β sample_gpu_poor.py completed 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" | |
] | |
subprocess.Popen(cmd) | |
def run_gradio_ui(): | |
print("π’ Starting gradio_audio.py UI...") | |
cmd = ["python3", "hymm_gradio/gradio_audio.py"] | |
subprocess.Popen(cmd) | |
def main(): | |
if os.path.isfile(CHECKPOINT_FP8_FILE): | |
print("β Model checkpoint already exists. Skipping download.") | |
else: | |
download_model() | |
run_sample_gpu_poor() | |
# Optional: Start Flask and Gradio UIs after poor sample run | |
run_flask_audio() | |
time.sleep(5) | |
run_gradio_ui() | |
if __name__ == "__main__": | |
main() |