rahul7star commited on
Commit
55d5b92
·
verified ·
1 Parent(s): f26c7a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -80
app.py CHANGED
@@ -1,84 +1,63 @@
1
  import os
2
- import sys
3
- import subprocess
4
- from huggingface_hub import list_repo_files
5
-
6
- MODEL_REPO = "tencent/HunyuanVideo-Avatar"
7
- REPO_ROOT_FOLDER = "ckpts" # folder inside repo to download
8
-
9
- BASE_DIR = os.getcwd()
10
- WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
11
- OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")
12
-
13
- def list_ckpt_files():
14
- print(f"🔍 Listing files under '{REPO_ROOT_FOLDER}' in repo {MODEL_REPO}...")
15
- all_files = list_repo_files(repo_id=MODEL_REPO, repo_type="model", revision="main")
16
- files = [f for f in all_files if f.startswith(REPO_ROOT_FOLDER + "/")]
17
- return files
18
-
19
- def download_ckpts():
20
- os.makedirs(WEIGHTS_DIR, exist_ok=True)
21
- for filepath in list_ckpt_files():
22
- # Target path relative to weights directory
23
- relative_path = os.path.relpath(filepath, REPO_ROOT_FOLDER)
24
- target_path = os.path.join(WEIGHTS_DIR, REPO_ROOT_FOLDER, relative_path)
25
-
26
- # Skip if already exists
27
- if os.path.exists(target_path):
28
- print(f"✅ File exists: {target_path}")
29
- continue
30
-
31
- # Create dirs if needed
32
- os.makedirs(os.path.dirname(target_path), exist_ok=True)
33
-
34
- # Download the file blob from HF repo using huggingface_hub api (requires v0.14+)
35
- print(f"⬇️ Downloading {filepath} to {target_path} ...")
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  try:
37
- from huggingface_hub import hf_hub_download
38
- hf_hub_download(repo_id=MODEL_REPO, filename=filepath, local_dir=os.path.dirname(target_path), local_dir_use_symlinks=False)
39
- except ImportError:
40
- print("⚠️ hf_hub_download not available, please upgrade huggingface_hub")
41
- sys.exit(1)
42
-
43
- def run_sample_gpu_poor():
44
- checkpoint_fp8 = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")
45
- if not os.path.isfile(checkpoint_fp8):
46
- print(f"❌ Checkpoint file not found at {checkpoint_fp8}. Cannot run sampling.")
47
- sys.exit(1)
48
-
49
- cmd = [
50
- "python3", "hymm_sp/sample_gpu_poor.py",
51
- "--input", "assets/test.csv",
52
- "--ckpt", checkpoint_fp8,
53
- "--sample-n-frames", "129",
54
- "--seed", "128",
55
- "--image-size", "704",
56
- "--cfg-scale", "7.5",
57
- "--infer-steps", "50",
58
- "--use-deepcache", "1",
59
- "--flow-shift-eval-video", "5.0",
60
- "--save-path", OUTPUT_BASEPATH,
61
- "--use-fp8",
62
- "--cpu-offload",
63
- "--infer-min"
64
- ]
65
-
66
- env = os.environ.copy()
67
- env["PYTHONPATH"] = "./"
68
- env["MODEL_BASE"] = WEIGHTS_DIR
69
- env["CPU_OFFLOAD"] = "1"
70
- env["CUDA_VISIBLE_DEVICES"] = "0"
71
-
72
- print("🎬 Running sample_gpu_poor.py ...")
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 main():
80
- download_ckpts()
81
- run_sample_gpu_poor()
82
 
83
  if __name__ == "__main__":
84
- main()
 
 
 
1
  import os
2
+ from huggingface_hub import hf_hub_download
3
+
4
+ REPO_ID = "tencent/HunyuanVideo-Avatar"
5
+ BASE_PATH = "ckpts"
6
+ LOCAL_BASE = os.path.join(os.getcwd(), "weights", "ckpts")
7
+
8
+ # List of essential files/folders to download (you can expand this if needed)
9
+ ESSENTIAL_PATHS = [
10
+ # Transformers checkpoints
11
+ "hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt",
12
+ "hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt",
13
+ "hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt",
14
+
15
+ # VAE
16
+ "hunyuan-video-t2v-720p/vae/config.json",
17
+ "hunyuan-video-t2v-720p/vae/pytorch_model.pt",
18
+
19
+ # llava_llama_image shard files (adjust count if needed)
20
+ "llava_llama_image/model-00001-of-00004.safetensors",
21
+ "llava_llama_image/model-00002-of-00004.safetensors",
22
+ "llava_llama_image/model-00003-of-00004.safetensors",
23
+ "llava_llama_image/model-00004-of-00004.safetensors",
24
+ "llava_llama_image/config.json",
25
+
26
+ # text_encoder_2
27
+ "text_encoder_2/config.json",
28
+ "text_encoder_2/pytorch_model.bin",
29
+
30
+ # whisper-tiny
31
+ "whisper-tiny/config.json",
32
+ "whisper-tiny/pytorch_model.bin",
33
+ "whisper-tiny/tokenizer.json",
34
+ "whisper-tiny/tokenizer_config.json",
35
+ "whisper-tiny/vocab.json",
36
+
37
+ # det_align
38
+ "det_align/config.json",
39
+ "det_align/pytorch_model.bin",
40
+ ]
41
+
42
+ def download_files():
43
+ for relative_path in ESSENTIAL_PATHS:
44
+ source_path = f"{BASE_PATH}/{relative_path}"
45
+ local_dir = os.path.join(LOCAL_BASE, os.path.dirname(relative_path))
46
+ os.makedirs(local_dir, exist_ok=True)
47
+
48
+ print(f"⬇️ Downloading {source_path} ...")
49
  try:
50
+ hf_hub_download(
51
+ repo_id=REPO_ID,
52
+ filename=source_path,
53
+ repo_type="model",
54
+ local_dir=local_dir,
55
+ local_dir_use_symlinks=False
56
+ )
57
+ except Exception as e:
58
+ print(f"❌ Failed to download {source_path}: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  if __name__ == "__main__":
61
+ download_files()
62
+ print("\n✅ All selected model weights downloaded to:")
63
+ print(f"{os.path.abspath(LOCAL_BASE)}")