rahul7star commited on
Commit
e794b4c
Β·
verified Β·
1 Parent(s): 0e7cb07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -75
app.py CHANGED
@@ -1,50 +1,64 @@
1
  import os
2
  import sys
3
  import subprocess
4
- import time
5
- from huggingface_hub import hf_hub_download
6
-
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
- # Download specific files from Hugging Face repo
12
- def download_checkpoints():
13
- os.makedirs(WEIGHTS_DIR, exist_ok=True)
14
- print("⬇️ Downloading necessary checkpoint files...")
15
-
16
- try:
17
- # Download FP8 checkpoint
18
- checkpoint_fp8 = hf_hub_download(
19
- repo_id="tencent/HunyuanVideo-Avatar",
20
- filename="ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt",
21
- cache_dir=WEIGHTS_DIR,
22
- local_dir=WEIGHTS_DIR,
23
- local_dir_use_symlinks=False
24
- )
25
-
26
- # Download normal checkpoint for Flask/Gradio UI
27
- checkpoint = hf_hub_download(
28
- repo_id="tencent/HunyuanVideo-Avatar",
29
- filename="ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt",
30
- cache_dir=WEIGHTS_DIR,
31
- local_dir=WEIGHTS_DIR,
32
- local_dir_use_symlinks=False
33
- )
34
-
35
- return checkpoint, checkpoint_fp8
36
-
37
- except Exception as e:
38
- print(f"❌ Error during checkpoint download: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  sys.exit(1)
40
 
41
- def run_sample_gpu_poor(checkpoint_fp8_path):
42
- print("🎬 Running sample_gpu_poor.py...")
43
 
44
  cmd = [
45
  "python3", "hymm_sp/sample_gpu_poor.py",
46
  "--input", "assets/test.csv",
47
- "--ckpt", checkpoint_fp8_path,
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
- # Step 1: Download only needed files from Hugging Face repo
101
- checkpoint, checkpoint_fp8 = download_checkpoints()
102
-
103
- # Step 2: Run poor sample video generation
104
- run_sample_gpu_poor(checkpoint_fp8)
105
 
106
- # Step 3: Launch Flask + Gradio UIs
107
- run_flask_audio(checkpoint)
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()