Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,71 @@
|
|
1 |
import os
|
2 |
import sys
|
|
|
3 |
import subprocess
|
4 |
-
import gradio as gr
|
5 |
-
from huggingface_hub import hf_hub_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 |
ESSENTIAL_PATHS = [
|
13 |
-
# Transformers
|
14 |
-
#"hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt",
|
15 |
"hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt",
|
16 |
-
#"hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt",
|
17 |
-
|
18 |
-
# VAE
|
19 |
-
"hunyuan-video-t2v-720p/vae/config.json",
|
20 |
-
"hunyuan-video-t2v-720p/vae/pytorch_model.pt",
|
21 |
-
|
22 |
-
# # llava_llama_image
|
23 |
-
# "llava_llama_image/model-00001-of-00004.safetensors",
|
24 |
-
# "llava_llama_image/model-00002-of-00004.safetensors",
|
25 |
-
# "llava_llama_image/model-00003-of-00004.safetensors",
|
26 |
-
# "llava_llama_image/model-00004-of-00004.safetensors",
|
27 |
-
# "llava_llama_image/config.json",
|
28 |
-
|
29 |
-
# text_encoder_2
|
30 |
-
"text_encoder_2/config.json",
|
31 |
-
"text_encoder_2/pytorch_model.bin",
|
32 |
-
|
33 |
-
# whisper-tiny
|
34 |
-
"whisper-tiny/config.json",
|
35 |
-
"whisper-tiny/pytorch_model.bin",
|
36 |
-
"whisper-tiny/tokenizer.json",
|
37 |
-
"whisper-tiny/tokenizer_config.json",
|
38 |
-
"whisper-tiny/vocab.json",
|
39 |
-
|
40 |
-
# det_align
|
41 |
-
"det_align/config.json",
|
42 |
-
"det_align/pytorch_model.bin",
|
43 |
]
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
if os.path.exists(local_path):
|
52 |
-
|
53 |
continue
|
54 |
|
55 |
-
|
56 |
try:
|
57 |
-
logs.append(f"β¬οΈ Downloading: {path}")
|
58 |
hf_hub_download(
|
59 |
repo_id=MODEL_REPO,
|
60 |
-
filename=
|
61 |
local_dir=WEIGHTS_DIR,
|
62 |
local_dir_use_symlinks=False,
|
63 |
)
|
64 |
except Exception as e:
|
65 |
-
|
66 |
|
67 |
-
return "\n".join(logs)
|
68 |
|
69 |
def run_sample_gpu_poor():
|
70 |
ckpt_fp8 = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")
|
71 |
|
72 |
if not os.path.isfile(ckpt_fp8):
|
73 |
-
|
|
|
74 |
|
75 |
cmd = [
|
76 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
@@ -95,22 +90,24 @@ def run_sample_gpu_poor():
|
|
95 |
env["CPU_OFFLOAD"] = "1"
|
96 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
97 |
|
|
|
98 |
result = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
|
|
99 |
if result.returncode != 0:
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
log2 = run_sample_gpu_poor()
|
106 |
-
return f"{log1}\n\n---\n\n{log2}"
|
107 |
|
108 |
-
# Gradio UI
|
109 |
-
with gr.Blocks() as demo:
|
110 |
-
gr.Markdown("## π¦ Download Selective Checkpoints + Run sample_gpu_poor.py")
|
111 |
-
output = gr.Textbox(lines=30, label="Logs")
|
112 |
-
button = gr.Button("π Download + Run")
|
113 |
-
button.click(fn=download_and_run, outputs=output)
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
-
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
4 |
import subprocess
|
|
|
|
|
5 |
|
6 |
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
7 |
BASE_DIR = os.getcwd()
|
8 |
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
|
9 |
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")
|
10 |
|
11 |
+
|
12 |
+
# Only download this specific file from transformers
|
13 |
ESSENTIAL_PATHS = [
|
|
|
|
|
14 |
"hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
]
|
16 |
|
17 |
+
# Download everything from these folders
|
18 |
+
FULL_DIRS = [
|
19 |
+
"hunyuan-video-t2v-720p/vae",
|
20 |
+
#"llava_llama_image",
|
21 |
+
"text_encoder_2",
|
22 |
+
"whisper-tiny",
|
23 |
+
"det_align",
|
24 |
+
]
|
25 |
+
|
26 |
+
|
27 |
+
def list_ckpt_files():
|
28 |
+
"""Return a list of files to download: specific files + all from some folders."""
|
29 |
+
try:
|
30 |
+
all_files = list_repo_files(MODEL_REPO)
|
31 |
+
except Exception as e:
|
32 |
+
print(f"β Failed to list files from {MODEL_REPO}: {e}")
|
33 |
+
return []
|
34 |
+
|
35 |
+
files_to_download = ESSENTIAL_PATHS.copy()
|
36 |
+
for path in all_files:
|
37 |
+
if any(path.startswith(folder + "/") for folder in FULL_DIRS):
|
38 |
+
files_to_download.append(path)
|
39 |
|
40 |
+
return files_to_download
|
41 |
+
|
42 |
+
|
43 |
+
def download_ckpts(files):
|
44 |
+
"""Download selected files to local directory, preserving structure."""
|
45 |
+
for file_path in files:
|
46 |
+
local_path = os.path.join(WEIGHTS_DIR, file_path)
|
47 |
if os.path.exists(local_path):
|
48 |
+
print(f"β
Already exists: {local_path}")
|
49 |
continue
|
50 |
|
51 |
+
print(f"β¬οΈ Downloading: {file_path}")
|
52 |
try:
|
|
|
53 |
hf_hub_download(
|
54 |
repo_id=MODEL_REPO,
|
55 |
+
filename=file_path,
|
56 |
local_dir=WEIGHTS_DIR,
|
57 |
local_dir_use_symlinks=False,
|
58 |
)
|
59 |
except Exception as e:
|
60 |
+
print(f"β Failed to download {file_path}: {e}")
|
61 |
|
|
|
62 |
|
63 |
def run_sample_gpu_poor():
|
64 |
ckpt_fp8 = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")
|
65 |
|
66 |
if not os.path.isfile(ckpt_fp8):
|
67 |
+
print(f"β Missing checkpoint: {ckpt_fp8}")
|
68 |
+
return
|
69 |
|
70 |
cmd = [
|
71 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
|
|
90 |
env["CPU_OFFLOAD"] = "1"
|
91 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
92 |
|
93 |
+
print("π Running sample_gpu_poor.py...")
|
94 |
result = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
95 |
+
|
96 |
if result.returncode != 0:
|
97 |
+
print(f"β sample_gpu_poor.py failed:\n{result.stderr}")
|
98 |
+
else:
|
99 |
+
print("β
sample_gpu_poor.py ran successfully!")
|
100 |
+
|
101 |
+
|
102 |
+
def main():
|
103 |
+
files = list_ckpt_files()
|
104 |
+
if not files:
|
105 |
+
print("β No checkpoint files found in repo under ckpts folder.")
|
106 |
+
sys.exit(1)
|
107 |
|
108 |
+
download_ckpts(files)
|
109 |
+
run_sample_gpu_poor()
|
|
|
|
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
+
main()
|