Spaces:
Paused
Paused
gg
Browse files
app_g.py
CHANGED
@@ -11,17 +11,24 @@ import sys
|
|
11 |
from huggingface_hub import snapshot_download
|
12 |
|
13 |
# === Setup Paths ===
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
MODEL_ZOO_DIR = os.path.join(PUSA_ROOT, "model_zoo")
|
16 |
WAN_SUBFOLDER = "Wan2.1-T2V-14B"
|
17 |
WAN_MODEL_PATH = os.path.join(MODEL_ZOO_DIR, WAN_SUBFOLDER)
|
18 |
LORA_PATH = os.path.join(MODEL_ZOO_DIR, "pusa_v1.pt")
|
19 |
|
20 |
-
# Add PUSA_ROOT to sys.path so Python can
|
21 |
if PUSA_ROOT not in sys.path:
|
22 |
sys.path.insert(0, PUSA_ROOT)
|
23 |
|
24 |
-
# Validate
|
25 |
DIFFSYNTH_PATH = os.path.join(PUSA_ROOT, "diffsynth")
|
26 |
if not os.path.exists(DIFFSYNTH_PATH):
|
27 |
raise RuntimeError(
|
@@ -29,8 +36,10 @@ if not os.path.exists(DIFFSYNTH_PATH):
|
|
29 |
f"Ensure PusaV1 is correctly cloned and folder structure is intact."
|
30 |
)
|
31 |
|
32 |
-
# === Ensure
|
33 |
def ensure_model_downloaded():
|
|
|
|
|
34 |
if not os.path.exists(MODEL_ZOO_DIR):
|
35 |
print("Downloading RaphaelLiu/PusaV1 to ./PusaV1/model_zoo ...")
|
36 |
snapshot_download(
|
@@ -40,6 +49,8 @@ def ensure_model_downloaded():
|
|
40 |
local_dir_use_symlinks=False,
|
41 |
)
|
42 |
print("β
PusaV1 base model downloaded.")
|
|
|
|
|
43 |
|
44 |
if not os.path.exists(WAN_MODEL_PATH):
|
45 |
print("Downloading Wan-AI/Wan2.1-T2V-14B to ./PusaV1/model_zoo/Wan2.1-T2V-14B ...")
|
@@ -50,14 +61,18 @@ def ensure_model_downloaded():
|
|
50 |
local_dir_use_symlinks=False,
|
51 |
)
|
52 |
print("β
Wan2.1-T2V-14B model downloaded.")
|
|
|
|
|
53 |
|
54 |
if not os.path.exists(LORA_PATH):
|
55 |
raise FileNotFoundError(
|
56 |
-
f"Expected LoRA weights 'pusa_v1.pt' not found at {LORA_PATH}. "
|
57 |
-
f"Please
|
58 |
)
|
|
|
|
|
59 |
|
60 |
-
#
|
61 |
print(f"\nπ Verifying files under: {MODEL_ZOO_DIR}\n")
|
62 |
for root, dirs, files in os.walk(MODEL_ZOO_DIR):
|
63 |
for file in files:
|
|
|
11 |
from huggingface_hub import snapshot_download
|
12 |
|
13 |
# === Setup Paths ===
|
14 |
+
import os
|
15 |
+
import sys
|
16 |
+
from huggingface_hub import snapshot_download
|
17 |
+
|
18 |
+
# === Robust Base Path ===
|
19 |
+
# Ensures compatibility inside Hugging Face Spaces (or any container)
|
20 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
21 |
+
PUSA_ROOT = os.path.join(BASE_DIR, "PusaV1")
|
22 |
MODEL_ZOO_DIR = os.path.join(PUSA_ROOT, "model_zoo")
|
23 |
WAN_SUBFOLDER = "Wan2.1-T2V-14B"
|
24 |
WAN_MODEL_PATH = os.path.join(MODEL_ZOO_DIR, WAN_SUBFOLDER)
|
25 |
LORA_PATH = os.path.join(MODEL_ZOO_DIR, "pusa_v1.pt")
|
26 |
|
27 |
+
# Add PUSA_ROOT to sys.path so Python can import diffsynth
|
28 |
if PUSA_ROOT not in sys.path:
|
29 |
sys.path.insert(0, PUSA_ROOT)
|
30 |
|
31 |
+
# === Validate diffsynth ===
|
32 |
DIFFSYNTH_PATH = os.path.join(PUSA_ROOT, "diffsynth")
|
33 |
if not os.path.exists(DIFFSYNTH_PATH):
|
34 |
raise RuntimeError(
|
|
|
36 |
f"Ensure PusaV1 is correctly cloned and folder structure is intact."
|
37 |
)
|
38 |
|
39 |
+
# === Ensure models exist, skip download if already present ===
|
40 |
def ensure_model_downloaded():
|
41 |
+
print("π Checking model presence...\n")
|
42 |
+
|
43 |
if not os.path.exists(MODEL_ZOO_DIR):
|
44 |
print("Downloading RaphaelLiu/PusaV1 to ./PusaV1/model_zoo ...")
|
45 |
snapshot_download(
|
|
|
49 |
local_dir_use_symlinks=False,
|
50 |
)
|
51 |
print("β
PusaV1 base model downloaded.")
|
52 |
+
else:
|
53 |
+
print("β
PusaV1 base folder already exists.")
|
54 |
|
55 |
if not os.path.exists(WAN_MODEL_PATH):
|
56 |
print("Downloading Wan-AI/Wan2.1-T2V-14B to ./PusaV1/model_zoo/Wan2.1-T2V-14B ...")
|
|
|
61 |
local_dir_use_symlinks=False,
|
62 |
)
|
63 |
print("β
Wan2.1-T2V-14B model downloaded.")
|
64 |
+
else:
|
65 |
+
print("β
Wan2.1-T2V-14B folder already exists.")
|
66 |
|
67 |
if not os.path.exists(LORA_PATH):
|
68 |
raise FileNotFoundError(
|
69 |
+
f"β Expected LoRA weights 'pusa_v1.pt' not found at {LORA_PATH}. "
|
70 |
+
f"Please make sure it exists in your repo."
|
71 |
)
|
72 |
+
else:
|
73 |
+
print("β
LoRA weights (pusa_v1.pt) found.")
|
74 |
|
75 |
+
# === List contents of model_zoo for verification
|
76 |
print(f"\nπ Verifying files under: {MODEL_ZOO_DIR}\n")
|
77 |
for root, dirs, files in os.walk(MODEL_ZOO_DIR):
|
78 |
for file in files:
|