rahul7star commited on
Commit
a98af42
Β·
verified Β·
1 Parent(s): 295aa02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -34
app.py CHANGED
@@ -2,65 +2,80 @@ import os
2
  import sys
3
  import subprocess
4
  import gradio as gr
5
- from huggingface_hub import list_repo_files, 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
- # Specific file to include from transformers/
13
- ALLOWED_TRANSFORMER_FILE = "ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt"
 
 
 
14
 
15
- def list_ckpt_files():
16
- all_files = list_repo_files(repo_id=MODEL_REPO, repo_type="model", revision="main")
 
17
 
18
- filtered_files = []
19
- for f in all_files:
20
- # Only allow this one file from transformers/
21
- if f.startswith("ckpts/hunyuan-video-t2v-720p/transformers/"):
22
- if f == ALLOWED_TRANSFORMER_FILE:
23
- filtered_files.append(f)
24
- else:
25
- filtered_files.append(f)
26
- return filtered_files
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def download_ckpts():
29
- os.makedirs(WEIGHTS_DIR, exist_ok=True)
30
  logs = []
 
31
 
32
- for filepath in list_ckpt_files():
33
- relative_path = os.path.relpath(filepath, "ckpts")
34
- target_path = os.path.join(WEIGHTS_DIR, "ckpts", relative_path)
35
-
36
- if os.path.exists(target_path):
37
- logs.append(f"βœ… Exists: {target_path}")
38
  continue
39
 
40
- os.makedirs(os.path.dirname(target_path), exist_ok=True)
41
- logs.append(f"⬇️ Downloading: {filepath}")
42
  try:
 
43
  hf_hub_download(
44
  repo_id=MODEL_REPO,
45
- filename=filepath,
46
- local_dir=os.path.dirname(target_path),
47
- local_dir_use_symlinks=False
48
  )
49
  except Exception as e:
50
- logs.append(f"❌ Failed to download {filepath}: {e}")
 
51
  return "\n".join(logs)
52
 
53
  def run_sample_gpu_poor():
54
- checkpoint_fp8 = os.path.join(
55
- WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt"
56
- )
57
- if not os.path.isfile(checkpoint_fp8):
58
- return f"❌ Missing checkpoint: {checkpoint_fp8}"
59
 
60
  cmd = [
61
  "python3", "hymm_sp/sample_gpu_poor.py",
62
  "--input", "assets/test.csv",
63
- "--ckpt", checkpoint_fp8,
64
  "--sample-n-frames", "129",
65
  "--seed", "128",
66
  "--image-size", "704",
@@ -92,7 +107,7 @@ def download_and_run():
92
 
93
  # Gradio UI
94
  with gr.Blocks() as demo:
95
- gr.Markdown("## πŸ“¦ Download All Checkpoints (Except Only One File from Transformers)")
96
  output = gr.Textbox(lines=30, label="Logs")
97
  button = gr.Button("πŸš€ Download + Run")
98
  button.click(fn=download_and_run, outputs=output)
 
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=os.path.dirname(local_path),
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",
77
  "--input", "assets/test.csv",
78
+ "--ckpt", ckpt_fp8,
79
  "--sample-n-frames", "129",
80
  "--seed", "128",
81
  "--image-size", "704",
 
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)