Spaces:
Running
Running
Update GhostPackDemo/install.py
Browse files- GhostPackDemo/install.py +45 -41
GhostPackDemo/install.py
CHANGED
|
@@ -1,60 +1,64 @@
|
|
| 1 |
# install.py
|
| 2 |
#!/usr/bin/env python3
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
ENV_DIR = "venv"
|
| 12 |
-
CACHE_DIR = "hf_download"
|
| 13 |
-
MODEL_ID = "hunyuanvideo-community/HunyuanVideo"
|
| 14 |
-
|
| 15 |
-
def run(cmd):
|
| 16 |
-
print(f"> {' '.join(cmd)}")
|
| 17 |
subprocess.check_call(cmd)
|
| 18 |
|
| 19 |
-
def
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# CUDA/GPU check
|
| 30 |
-
if shutil.which("nvidia-smi") is None:
|
| 31 |
-
print("Warning: nvidia-smi not found; CUDA will be unavailable")
|
| 32 |
-
if shutil.which("nvcc") is None:
|
| 33 |
-
print("Warning: nvcc not found; install CUDA toolkit for best performance")
|
| 34 |
-
|
| 35 |
-
# Virtual env
|
| 36 |
-
if not os.path.isdir(ENV_DIR):
|
| 37 |
-
run([sys.executable, "-m", "venv", ENV_DIR])
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
pip = os.path.join(ENV_DIR, "Scripts", "pip.exe")
|
| 41 |
py = os.path.join(ENV_DIR, "Scripts", "python.exe")
|
| 42 |
else:
|
| 43 |
pip = os.path.join(ENV_DIR, "bin", "pip")
|
| 44 |
py = os.path.join(ENV_DIR, "bin", "python")
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
run([pip, "install", "--upgrade", "pip"])
|
| 48 |
run([pip, "install", "-r", "requirements.txt"])
|
| 49 |
|
| 50 |
-
|
| 51 |
-
os.makedirs(CACHE_DIR, exist_ok=True)
|
| 52 |
run([py, "-c", "from diffusers_helper.hf_login import login; login()"])
|
| 53 |
-
run([py, "-c",
|
| 54 |
-
f"from huggingface_hub import snapshot_download; snapshot_download('{MODEL_ID}', cache_dir='{CACHE_DIR}')"])
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
main()
|
|
|
|
| 1 |
# install.py
|
| 2 |
#!/usr/bin/env python3
|
| 3 |
+
import os, sys, subprocess, shutil, platform, venv
|
| 4 |
+
|
| 5 |
+
ENV_DIR = "venv"
|
| 6 |
+
CACHE_DIR = "hf_download"
|
| 7 |
+
MODEL_ID = "hunyuanvideo-community/HunyuanVideo"
|
| 8 |
+
|
| 9 |
+
def run(cmd: list[str]):
|
| 10 |
+
print("❯", *cmd, flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
subprocess.check_call(cmd)
|
| 12 |
|
| 13 |
+
def ensure_python():
|
| 14 |
+
if sys.version_info < (3, 8):
|
| 15 |
+
sys.exit("❌ Python 3.8 or newer required.")
|
| 16 |
+
|
| 17 |
+
def cuda_info():
|
| 18 |
+
if shutil.which("nvidia-smi"):
|
| 19 |
+
run(["nvidia-smi", "--query-gpu=name,memory.total,driver_version", "--format=csv"])
|
| 20 |
+
else:
|
| 21 |
+
print("⚠️ CUDA GPU not found – fall-back to CPU (slow).")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
def create_venv() -> tuple[str, str]:
|
| 24 |
+
if not os.path.isdir(ENV_DIR):
|
| 25 |
+
print("📦 Creating virtual environment…")
|
| 26 |
+
venv.create(ENV_DIR, with_pip=True)
|
| 27 |
+
if platform.system() == "Windows":
|
| 28 |
pip = os.path.join(ENV_DIR, "Scripts", "pip.exe")
|
| 29 |
py = os.path.join(ENV_DIR, "Scripts", "python.exe")
|
| 30 |
else:
|
| 31 |
pip = os.path.join(ENV_DIR, "bin", "pip")
|
| 32 |
py = os.path.join(ENV_DIR, "bin", "python")
|
| 33 |
+
return pip, py
|
| 34 |
|
| 35 |
+
def install_deps(pip: str):
|
| 36 |
run([pip, "install", "--upgrade", "pip"])
|
| 37 |
run([pip, "install", "-r", "requirements.txt"])
|
| 38 |
|
| 39 |
+
def hf_login(py: str):
|
|
|
|
| 40 |
run([py, "-c", "from diffusers_helper.hf_login import login; login()"])
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
def download_model(py: str):
|
| 43 |
+
os.makedirs(CACHE_DIR, exist_ok=True)
|
| 44 |
+
code = (
|
| 45 |
+
f"from huggingface_hub import snapshot_download;"
|
| 46 |
+
f"snapshot_download('{MODEL_ID}', cache_dir='{CACHE_DIR}', resume_download=True)"
|
| 47 |
+
)
|
| 48 |
+
run([py, "-c", code])
|
| 49 |
+
|
| 50 |
+
def main():
|
| 51 |
+
ensure_python()
|
| 52 |
+
cuda_info()
|
| 53 |
+
pip, py = create_venv()
|
| 54 |
+
install_deps(pip)
|
| 55 |
+
hf_login(py)
|
| 56 |
+
download_model(py)
|
| 57 |
+
print("\n✅ Setup complete. Activate with:")
|
| 58 |
+
if platform.system() == "Windows":
|
| 59 |
+
print(f" {ENV_DIR}\\Scripts\\Activate.ps1 && python ghostpack_main_fixed.py --inbrowser")
|
| 60 |
+
else:
|
| 61 |
+
print(f" source {ENV_DIR}/bin/activate && python ghostpack_main_fixed.py --inbrowser")
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
main()
|