Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,117 +2,51 @@ import os
|
|
2 |
import sys
|
3 |
import subprocess
|
4 |
import time
|
|
|
|
|
5 |
from huggingface_hub import snapshot_download
|
6 |
|
7 |
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
8 |
BASE_DIR = os.getcwd()
|
9 |
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
|
10 |
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
"transformers",
|
18 |
-
"mp_rank_00_model_states.pt"
|
19 |
-
)
|
20 |
-
CHECKPOINT_FP8_FILE = os.path.join(
|
21 |
-
WEIGHTS_DIR,
|
22 |
-
"ckpts",
|
23 |
-
"hunyuan-video-t2v-720p",
|
24 |
-
"transformers",
|
25 |
-
"mp_rank_00_model_states_fp8.pt"
|
26 |
-
)
|
27 |
|
28 |
def download_model():
|
29 |
-
print("β¬οΈ
|
30 |
os.makedirs(WEIGHTS_DIR, exist_ok=True)
|
31 |
|
32 |
snapshot_download(
|
33 |
repo_id=MODEL_REPO,
|
34 |
local_dir=WEIGHTS_DIR,
|
35 |
-
local_dir_use_symlinks=False
|
|
|
36 |
)
|
37 |
|
38 |
if not os.path.isfile(CHECKPOINT_FILE):
|
39 |
-
print(f"β Checkpoint
|
40 |
sys.exit(1)
|
41 |
-
|
42 |
if not os.path.isfile(CHECKPOINT_FP8_FILE):
|
43 |
-
print(f"β FP8
|
44 |
-
sys.exit(1)
|
45 |
-
|
46 |
-
print("β
Model downloaded successfully.")
|
47 |
-
|
48 |
-
def run_sample_gpu_poor():
|
49 |
-
print("π¬ Running sample_gpu_poor.py...")
|
50 |
-
cmd = [
|
51 |
-
"python3", "hymm_sp/sample_gpu_poor.py",
|
52 |
-
"--input", "assets/test.csv",
|
53 |
-
"--ckpt", CHECKPOINT_FP8_FILE,
|
54 |
-
"--sample-n-frames", "129",
|
55 |
-
"--seed", "128",
|
56 |
-
"--image-size", "704",
|
57 |
-
"--cfg-scale", "7.5",
|
58 |
-
"--infer-steps", "50",
|
59 |
-
"--use-deepcache", "1",
|
60 |
-
"--flow-shift-eval-video", "5.0",
|
61 |
-
"--save-path", OUTPUT_BASEPATH,
|
62 |
-
"--use-fp8",
|
63 |
-
"--cpu-offload",
|
64 |
-
"--infer-min"
|
65 |
-
]
|
66 |
-
|
67 |
-
env = os.environ.copy()
|
68 |
-
env["PYTHONPATH"] = "./"
|
69 |
-
env["MODEL_BASE"] = WEIGHTS_DIR
|
70 |
-
env["CPU_OFFLOAD"] = "1"
|
71 |
-
env["CUDA_VISIBLE_DEVICES"] = "0"
|
72 |
-
|
73 |
-
proc = subprocess.run(cmd, env=env)
|
74 |
-
if proc.returncode != 0:
|
75 |
-
print("β sample_gpu_poor.py failed.")
|
76 |
sys.exit(1)
|
77 |
-
print("β
sample_gpu_poor.py completed successfully.")
|
78 |
-
|
79 |
-
def run_flask_audio():
|
80 |
-
print("π Starting flask_audio.py...")
|
81 |
-
cmd = [
|
82 |
-
"torchrun",
|
83 |
-
"--nnodes=1",
|
84 |
-
"--nproc_per_node=8",
|
85 |
-
"--master_port=29605",
|
86 |
-
"hymm_gradio/flask_audio.py",
|
87 |
-
"--input", "assets/test.csv",
|
88 |
-
"--ckpt", CHECKPOINT_FILE,
|
89 |
-
"--sample-n-frames", "129",
|
90 |
-
"--seed", "128",
|
91 |
-
"--image-size", "704",
|
92 |
-
"--cfg-scale", "7.5",
|
93 |
-
"--infer-steps", "50",
|
94 |
-
"--use-deepcache", "1",
|
95 |
-
"--flow-shift-eval-video", "5.0"
|
96 |
-
]
|
97 |
-
subprocess.Popen(cmd)
|
98 |
-
|
99 |
-
def run_gradio_ui():
|
100 |
-
print("π’ Starting gradio_audio.py UI...")
|
101 |
-
cmd = ["python3", "hymm_gradio/gradio_audio.py"]
|
102 |
-
subprocess.Popen(cmd)
|
103 |
-
|
104 |
-
def main():
|
105 |
-
if os.path.isfile(CHECKPOINT_FILE) and os.path.isfile(CHECKPOINT_FP8_FILE):
|
106 |
-
print("β
Model checkpoint already exists. Skipping download.")
|
107 |
-
else:
|
108 |
-
download_model()
|
109 |
-
|
110 |
-
run_sample_gpu_poor()
|
111 |
-
|
112 |
-
# Optional: Start Flask and Gradio UIs after poor sample run
|
113 |
-
run_flask_audio()
|
114 |
-
time.sleep(5)
|
115 |
-
run_gradio_ui()
|
116 |
|
117 |
-
|
118 |
-
main()
|
|
|
2 |
import sys
|
3 |
import subprocess
|
4 |
import time
|
5 |
+
import shutil
|
6 |
+
import psutil
|
7 |
from huggingface_hub import snapshot_download
|
8 |
|
9 |
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
10 |
BASE_DIR = os.getcwd()
|
11 |
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
|
12 |
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")
|
13 |
+
CUSTOM_CACHE_DIR = "/data/hf_cache" # β
change if different
|
14 |
+
HF_HOME_ENV = {"HF_HOME": CUSTOM_CACHE_DIR}
|
15 |
+
|
16 |
+
# Paths to required checkpoints
|
17 |
+
CHECKPOINT_FILE = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states.pt")
|
18 |
+
CHECKPOINT_FP8_FILE = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")
|
19 |
+
|
20 |
+
def check_disk_space(min_free_gb=10):
|
21 |
+
total, used, free = shutil.disk_usage("/")
|
22 |
+
free_gb = free // (2**30)
|
23 |
+
print(f"πΎ Disk space: {free_gb}GB free")
|
24 |
+
if free_gb < min_free_gb:
|
25 |
+
print(f"β Not enough disk space. {free_gb}GB available, {min_free_gb}GB required.")
|
26 |
+
sys.exit(1)
|
27 |
|
28 |
+
def clear_hf_cache():
|
29 |
+
hf_cache = os.path.expanduser("~/.cache/huggingface")
|
30 |
+
if os.path.exists(hf_cache):
|
31 |
+
print("π§Ή Cleaning Hugging Face cache...")
|
32 |
+
shutil.rmtree(hf_cache)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def download_model():
|
35 |
+
print("β¬οΈ Downloading model to weights directory...")
|
36 |
os.makedirs(WEIGHTS_DIR, exist_ok=True)
|
37 |
|
38 |
snapshot_download(
|
39 |
repo_id=MODEL_REPO,
|
40 |
local_dir=WEIGHTS_DIR,
|
41 |
+
local_dir_use_symlinks=False,
|
42 |
+
**HF_HOME_ENV
|
43 |
)
|
44 |
|
45 |
if not os.path.isfile(CHECKPOINT_FILE):
|
46 |
+
print(f"β Checkpoint missing at {CHECKPOINT_FILE}")
|
47 |
sys.exit(1)
|
|
|
48 |
if not os.path.isfile(CHECKPOINT_FP8_FILE):
|
49 |
+
print(f"β FP8 Checkpoint missing at {CHECKPOINT_FP8_FILE}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
print("β
Model downloaded suc
|
|