rahul7star commited on
Commit
abcba3a
Β·
verified Β·
1 Parent(s): 318e971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -56
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
- def download_ckpts():
46
- logs = []
47
- os.makedirs(os.path.join(WEIGHTS_DIR, "ckpts"), exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- for path in ESSENTIAL_PATHS:
50
- local_path = os.path.join(WEIGHTS_DIR, "ckpts", path)
 
 
 
 
 
51
  if os.path.exists(local_path):
52
- logs.append(f"βœ… Exists: {path}")
53
  continue
54
 
55
- os.makedirs(os.path.dirname(local_path), exist_ok=True)
56
  try:
57
- logs.append(f"⬇️ Downloading: {path}")
58
  hf_hub_download(
59
  repo_id=MODEL_REPO,
60
- filename="ckpts/" + path,
61
  local_dir=WEIGHTS_DIR,
62
  local_dir_use_symlinks=False,
63
  )
64
  except Exception as e:
65
- logs.append(f"❌ Failed: {path} - {str(e)}")
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
- return f"❌ Missing checkpoint: {ckpt_fp8}"
 
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
- return f"❌ sample_gpu_poor.py failed:\n{result.stderr}"
101
- return f"βœ… sample_gpu_poor.py finished:\n{result.stdout}"
 
 
 
 
 
 
 
 
102
 
103
- def download_and_run():
104
- log1 = download_ckpts()
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
- demo.launch(share=False)
 
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()