Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,64 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
import subprocess
|
4 |
-
import
|
5 |
-
from
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
sys.exit(1)
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
44 |
cmd = [
|
45 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
46 |
"--input", "assets/test.csv",
|
47 |
-
"--ckpt",
|
48 |
"--sample-n-frames", "129",
|
49 |
"--seed", "128",
|
50 |
"--image-size", "704",
|
@@ -52,7 +66,7 @@ def run_sample_gpu_poor(checkpoint_fp8_path):
|
|
52 |
"--infer-steps", "50",
|
53 |
"--use-deepcache", "1",
|
54 |
"--flow-shift-eval-video", "5.0",
|
55 |
-
"--save-path", OUTPUT_BASEPATH,
|
56 |
"--use-fp8",
|
57 |
"--cpu-offload",
|
58 |
"--infer-min"
|
@@ -60,53 +74,25 @@ def run_sample_gpu_poor(checkpoint_fp8_path):
|
|
60 |
|
61 |
env = os.environ.copy()
|
62 |
env["PYTHONPATH"] = "./"
|
63 |
-
env["MODEL_BASE"] = WEIGHTS_DIR
|
64 |
env["CPU_OFFLOAD"] = "1"
|
65 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
66 |
|
|
|
67 |
proc = subprocess.run(cmd, env=env)
|
68 |
if proc.returncode != 0:
|
69 |
print("β sample_gpu_poor.py failed.")
|
70 |
sys.exit(1)
|
71 |
-
|
72 |
print("β
sample_gpu_poor.py completed successfully.")
|
73 |
|
74 |
-
def run_flask_audio(checkpoint_path):
|
75 |
-
print("π Starting flask_audio.py...")
|
76 |
-
cmd = [
|
77 |
-
"torchrun",
|
78 |
-
"--nnodes=1",
|
79 |
-
"--nproc_per_node=1",
|
80 |
-
"--master_port=29605",
|
81 |
-
"hymm_gradio/flask_audio.py",
|
82 |
-
"--input", "assets/test.csv",
|
83 |
-
"--ckpt", checkpoint_path,
|
84 |
-
"--sample-n-frames", "129",
|
85 |
-
"--seed", "128",
|
86 |
-
"--image-size", "704",
|
87 |
-
"--cfg-scale", "7.5",
|
88 |
-
"--infer-steps", "50",
|
89 |
-
"--use-deepcache", "1",
|
90 |
-
"--flow-shift-eval-video", "5.0"
|
91 |
-
]
|
92 |
-
subprocess.Popen(cmd)
|
93 |
-
|
94 |
-
def run_gradio_ui():
|
95 |
-
print("π’ Starting gradio_audio.py UI...")
|
96 |
-
cmd = ["python3", "hymm_gradio/gradio_audio.py"]
|
97 |
-
subprocess.Popen(cmd)
|
98 |
-
|
99 |
def main():
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
run_sample_gpu_poor(checkpoint_fp8)
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
time.sleep(5)
|
109 |
-
run_gradio_ui()
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
main()
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
import subprocess
|
4 |
+
from huggingface_hub import hf_hub_download, hf_hub_list
|
5 |
+
from pathlib import Path
|
6 |
+
|
7 |
+
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
8 |
+
BASE_DIR = Path.cwd()
|
9 |
+
WEIGHTS_DIR = BASE_DIR / "weights"
|
10 |
+
CKPTS_DIR = WEIGHTS_DIR / "ckpts"
|
11 |
+
|
12 |
+
# The root folder in the repo you want to download files from
|
13 |
+
REPO_ROOT_FOLDER = "ckpts"
|
14 |
+
|
15 |
+
# List all files under the folder 'ckpts' in the repo (recursively)
|
16 |
+
def list_ckpt_files():
|
17 |
+
print(f"π Listing files under '{REPO_ROOT_FOLDER}' in repo {MODEL_REPO}...")
|
18 |
+
files = hf_hub_list(repo_id=MODEL_REPO, repo_type="model", revision="main", allow_regex=f"^{REPO_ROOT_FOLDER}/.*")
|
19 |
+
return files
|
20 |
+
|
21 |
+
# Download all files in the list into weights/ckpts preserving folder structure
|
22 |
+
def download_ckpts(files):
|
23 |
+
print(f"β¬οΈ Downloading {len(files)} files under '{REPO_ROOT_FOLDER}' ...")
|
24 |
+
for file in files:
|
25 |
+
# Target local path preserving folder structure after 'ckpts/'
|
26 |
+
relative_path = Path(file).relative_to(REPO_ROOT_FOLDER)
|
27 |
+
local_path = CKPTS_DIR / relative_path
|
28 |
+
|
29 |
+
# Make sure directory exists
|
30 |
+
local_path.parent.mkdir(parents=True, exist_ok=True)
|
31 |
+
|
32 |
+
# Download the file if not present
|
33 |
+
if not local_path.is_file():
|
34 |
+
print(f"Downloading {file} -> {local_path}")
|
35 |
+
hf_hub_download(
|
36 |
+
repo_id=MODEL_REPO,
|
37 |
+
filename=file,
|
38 |
+
repo_type="model",
|
39 |
+
cache_dir=str(WEIGHTS_DIR),
|
40 |
+
local_dir=str(WEIGHTS_DIR),
|
41 |
+
local_dir_use_symlinks=False,
|
42 |
+
force_filename=str(local_path.name),
|
43 |
+
revision="main",
|
44 |
+
)
|
45 |
+
else:
|
46 |
+
print(f"File {local_path} already exists, skipping download.")
|
47 |
+
print("β
All checkpoint files downloaded.")
|
48 |
+
|
49 |
+
def run_sample_gpu_poor():
|
50 |
+
checkpoint_fp8 = CKPTS_DIR / "hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt"
|
51 |
+
if not checkpoint_fp8.is_file():
|
52 |
+
print(f"β Checkpoint file {checkpoint_fp8} not found!")
|
53 |
sys.exit(1)
|
54 |
|
55 |
+
OUTPUT_BASEPATH = BASE_DIR / "results-poor"
|
56 |
+
OUTPUT_BASEPATH.mkdir(parents=True, exist_ok=True)
|
57 |
|
58 |
cmd = [
|
59 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
60 |
"--input", "assets/test.csv",
|
61 |
+
"--ckpt", str(checkpoint_fp8),
|
62 |
"--sample-n-frames", "129",
|
63 |
"--seed", "128",
|
64 |
"--image-size", "704",
|
|
|
66 |
"--infer-steps", "50",
|
67 |
"--use-deepcache", "1",
|
68 |
"--flow-shift-eval-video", "5.0",
|
69 |
+
"--save-path", str(OUTPUT_BASEPATH),
|
70 |
"--use-fp8",
|
71 |
"--cpu-offload",
|
72 |
"--infer-min"
|
|
|
74 |
|
75 |
env = os.environ.copy()
|
76 |
env["PYTHONPATH"] = "./"
|
77 |
+
env["MODEL_BASE"] = str(WEIGHTS_DIR)
|
78 |
env["CPU_OFFLOAD"] = "1"
|
79 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
80 |
|
81 |
+
print("π¬ Running sample_gpu_poor.py...")
|
82 |
proc = subprocess.run(cmd, env=env)
|
83 |
if proc.returncode != 0:
|
84 |
print("β sample_gpu_poor.py failed.")
|
85 |
sys.exit(1)
|
|
|
86 |
print("β
sample_gpu_poor.py completed successfully.")
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def main():
|
89 |
+
files = list_ckpt_files()
|
90 |
+
if not files:
|
91 |
+
print("β No checkpoint files found in repo under ckpts folder.")
|
92 |
+
sys.exit(1)
|
|
|
93 |
|
94 |
+
download_ckpts(files)
|
95 |
+
run_sample_gpu_poor()
|
|
|
|
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
main()
|