rahul7star commited on
Commit
fedb718
Β·
verified Β·
1 Parent(s): bde65ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -11
app.py CHANGED
@@ -5,9 +5,11 @@ import time
5
  from huggingface_hub import snapshot_download
6
 
7
  MODEL_REPO = "tencent/HunyuanVideo-Avatar"
8
- BASE_DIR = os.getcwd() # current working directory absolute path
9
  WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
 
10
 
 
11
  CHECKPOINT_FILE = os.path.join(
12
  WEIGHTS_DIR,
13
  "ckpts",
@@ -15,9 +17,16 @@ CHECKPOINT_FILE = os.path.join(
15
  "transformers",
16
  "mp_rank_00_model_states.pt"
17
  )
 
 
 
 
 
 
 
18
 
19
  def download_model():
20
- print("⬇️ Model not found. Downloading with snapshot_download into weights directory...")
21
  os.makedirs(WEIGHTS_DIR, exist_ok=True)
22
 
23
  snapshot_download(
@@ -29,9 +38,44 @@ def download_model():
29
  if not os.path.isfile(CHECKPOINT_FILE):
30
  print(f"❌ Checkpoint file not found at {CHECKPOINT_FILE} after download.")
31
  sys.exit(1)
 
 
 
 
32
 
33
  print("βœ… Model downloaded successfully.")
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def run_flask_audio():
36
  print("πŸš€ Starting flask_audio.py...")
37
  cmd = [
@@ -50,24 +94,25 @@ def run_flask_audio():
50
  "--use-deepcache", "1",
51
  "--flow-shift-eval-video", "5.0"
52
  ]
53
- proc = subprocess.Popen(cmd)
54
- return proc
55
 
56
  def run_gradio_ui():
57
  print("🟒 Starting gradio_audio.py UI...")
58
  cmd = ["python3", "hymm_gradio/gradio_audio.py"]
59
- proc = subprocess.Popen(cmd)
60
- return proc
61
 
62
  def main():
63
- if os.path.isfile(CHECKPOINT_FILE):
64
  print("βœ… Model checkpoint already exists. Skipping download.")
65
  else:
66
  download_model()
67
 
68
- flask_proc = run_flask_audio()
69
- time.sleep(5) # Wait a bit for flask_audio.py to start
70
- gradio_proc = run_gradio_ui()
 
 
 
71
 
72
  if __name__ == "__main__":
73
- main()
 
5
  from huggingface_hub import snapshot_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 checkpoint to use in the poor sampling run
13
  CHECKPOINT_FILE = os.path.join(
14
  WEIGHTS_DIR,
15
  "ckpts",
 
17
  "transformers",
18
  "mp_rank_00_model_states.pt"
19
  )
20
+ CHECKPOINT_FP8_FILE = os.path.join(
21
+ WEIGHTS_DIR,
22
+ "ckpts",
23
+ "hunyuan-video-t2v-720p",
24
+ "transformers",
25
+ "mp_rank_00_model_states_fp8.pt"
26
+ )
27
 
28
  def download_model():
29
+ print("⬇️ Model not found. Downloading with snapshot_download into weights directory...")
30
  os.makedirs(WEIGHTS_DIR, exist_ok=True)
31
 
32
  snapshot_download(
 
38
  if not os.path.isfile(CHECKPOINT_FILE):
39
  print(f"❌ Checkpoint file not found at {CHECKPOINT_FILE} after download.")
40
  sys.exit(1)
41
+
42
+ if not os.path.isfile(CHECKPOINT_FP8_FILE):
43
+ print(f"❌ FP8 checkpoint file not found at {CHECKPOINT_FP8_FILE}. Cannot proceed with sample_gpu_poor.py.")
44
+ sys.exit(1)
45
 
46
  print("βœ… Model downloaded successfully.")
47
 
48
+ def run_sample_gpu_poor():
49
+ print("🎬 Running sample_gpu_poor.py...")
50
+ cmd = [
51
+ "python3", "hymm_sp/sample_gpu_poor.py",
52
+ "--input", "assets/test.csv",
53
+ "--ckpt", CHECKPOINT_FP8_FILE,
54
+ "--sample-n-frames", "129",
55
+ "--seed", "128",
56
+ "--image-size", "704",
57
+ "--cfg-scale", "7.5",
58
+ "--infer-steps", "50",
59
+ "--use-deepcache", "1",
60
+ "--flow-shift-eval-video", "5.0",
61
+ "--save-path", OUTPUT_BASEPATH,
62
+ "--use-fp8",
63
+ "--cpu-offload",
64
+ "--infer-min"
65
+ ]
66
+
67
+ env = os.environ.copy()
68
+ env["PYTHONPATH"] = "./"
69
+ env["MODEL_BASE"] = WEIGHTS_DIR
70
+ env["CPU_OFFLOAD"] = "1"
71
+ env["CUDA_VISIBLE_DEVICES"] = "0"
72
+
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 run_flask_audio():
80
  print("πŸš€ Starting flask_audio.py...")
81
  cmd = [
 
94
  "--use-deepcache", "1",
95
  "--flow-shift-eval-video", "5.0"
96
  ]
97
+ subprocess.Popen(cmd)
 
98
 
99
  def run_gradio_ui():
100
  print("🟒 Starting gradio_audio.py UI...")
101
  cmd = ["python3", "hymm_gradio/gradio_audio.py"]
102
+ subprocess.Popen(cmd)
 
103
 
104
  def main():
105
+ if os.path.isfile(CHECKPOINT_FILE) and os.path.isfile(CHECKPOINT_FP8_FILE):
106
  print("βœ… Model checkpoint already exists. Skipping download.")
107
  else:
108
  download_model()
109
 
110
+ run_sample_gpu_poor()
111
+
112
+ # Optional: Start Flask and Gradio UIs after poor sample run
113
+ run_flask_audio()
114
+ time.sleep(5)
115
+ run_gradio_ui()
116
 
117
  if __name__ == "__main__":
118
+ main()