Spaces:
Sleeping
Sleeping
futurespyhi
commited on
Commit
Β·
297dc31
1
Parent(s):
c87f4fd
1.modify the logic of downloading_xcodec_models: using git clone instead of huggingface_hub 2. modify .gitignore
Browse files- .gitignore +1 -0
- download_models.py +81 -72
.gitignore
CHANGED
|
@@ -108,6 +108,7 @@ flash_attn/
|
|
| 108 |
# bcakup files
|
| 109 |
packages.txt.backup
|
| 110 |
requirements.txt.backup
|
|
|
|
| 111 |
|
| 112 |
# test files
|
| 113 |
tests/
|
|
|
|
| 108 |
# bcakup files
|
| 109 |
packages.txt.backup
|
| 110 |
requirements.txt.backup
|
| 111 |
+
download_model.py.backup
|
| 112 |
|
| 113 |
# test files
|
| 114 |
tests/
|
download_models.py
CHANGED
|
@@ -5,77 +5,86 @@ Downloads required model files from Hugging Face Hub at runtime to avoid storage
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
|
|
|
| 8 |
import shutil
|
| 9 |
from pathlib import Path
|
| 10 |
-
from huggingface_hub import hf_hub_download, snapshot_download
|
| 11 |
|
| 12 |
|
| 13 |
def download_xcodec_models():
|
| 14 |
-
"""Download xcodec_mini_infer models
|
| 15 |
-
|
| 16 |
# Base path for xcodec models
|
| 17 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 18 |
-
|
| 19 |
-
print("π₯ Downloading xcodec_mini_infer models...")
|
| 20 |
-
|
| 21 |
try:
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
print(f"β Error downloading xcodec_mini_infer models: {e}")
|
| 35 |
-
|
| 36 |
-
# Try downloading individual essential files if full download fails
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
"
|
| 51 |
-
"decoders/
|
| 52 |
-
"decoders/decoder_151000.pth",
|
| 53 |
-
"decoders/config.yaml"
|
| 54 |
]
|
| 55 |
-
|
| 56 |
-
for
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
print(f"
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
return True
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
def ensure_model_availability():
|
|
@@ -86,28 +95,28 @@ def ensure_model_availability():
|
|
| 86 |
|
| 87 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 88 |
|
| 89 |
-
# Check if
|
| 90 |
-
|
| 91 |
-
xcodec_base / "
|
| 92 |
-
xcodec_base / "
|
| 93 |
-
xcodec_base / "
|
| 94 |
]
|
| 95 |
|
| 96 |
-
missing_files = [f for f in
|
| 97 |
|
| 98 |
if missing_files:
|
| 99 |
-
print(f"β οΈ Missing model files: {[
|
| 100 |
-
print("π Starting model download...")
|
| 101 |
-
|
| 102 |
success = download_xcodec_models()
|
| 103 |
-
|
| 104 |
if success:
|
| 105 |
print("β
Model download completed successfully!")
|
| 106 |
else:
|
| 107 |
-
print("β Model download failed.
|
| 108 |
return False
|
| 109 |
else:
|
| 110 |
-
print("β
All
|
| 111 |
|
| 112 |
return True
|
| 113 |
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
| 8 |
+
import subprocess
|
| 9 |
import shutil
|
| 10 |
from pathlib import Path
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def download_xcodec_models():
|
| 14 |
+
"""Download xcodec_mini_infer models using git clone (supports Git LFS)"""
|
| 15 |
+
|
| 16 |
# Base path for xcodec models
|
| 17 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 18 |
+
|
| 19 |
+
print("π₯ Downloading xcodec_mini_infer models using git clone...")
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
+
# Remove existing directory if it exists (might be empty or incomplete)
|
| 23 |
+
if xcodec_base.exists():
|
| 24 |
+
print("ποΈ Removing existing xcodec_mini_infer directory...")
|
| 25 |
+
shutil.rmtree(xcodec_base)
|
| 26 |
+
|
| 27 |
+
# Ensure parent directory exists
|
| 28 |
+
os.makedirs(xcodec_base.parent, exist_ok=True)
|
| 29 |
+
|
| 30 |
+
# Change to the parent directory for git clone
|
| 31 |
+
original_cwd = os.getcwd()
|
| 32 |
+
os.chdir(xcodec_base.parent)
|
| 33 |
+
|
|
|
|
|
|
|
|
|
|
| 34 |
try:
|
| 35 |
+
# Clone the repository using git (Spaces has git and git-lfs pre-installed)
|
| 36 |
+
print("π Cloning repository with Git LFS support...")
|
| 37 |
+
result = subprocess.run([
|
| 38 |
+
"git", "clone",
|
| 39 |
+
"https://huggingface.co/m-a-p/xcodec_mini_infer",
|
| 40 |
+
"xcodec_mini_infer"
|
| 41 |
+
], check=True, capture_output=True, text=True, timeout=600)
|
| 42 |
+
|
| 43 |
+
print("β
Successfully cloned xcodec_mini_infer repository")
|
| 44 |
+
|
| 45 |
+
# Verify critical decoder files exist (these are Git LFS files)
|
| 46 |
+
decoder_files = [
|
| 47 |
+
xcodec_base / "decoders" / "decoder_131000.pth",
|
| 48 |
+
xcodec_base / "decoders" / "decoder_151000.pth"
|
|
|
|
|
|
|
| 49 |
]
|
| 50 |
+
|
| 51 |
+
missing_decoders = [f for f in decoder_files if not f.exists()]
|
| 52 |
+
if missing_decoders:
|
| 53 |
+
print(f"β οΈ Decoder files missing: {[f.name for f in missing_decoders]}")
|
| 54 |
+
print("π Ensuring Git LFS files are downloaded...")
|
| 55 |
+
|
| 56 |
+
# Try to explicitly pull LFS files
|
| 57 |
+
os.chdir("xcodec_mini_infer")
|
| 58 |
+
subprocess.run(["git", "lfs", "pull"], check=True, capture_output=True, text=True, timeout=300)
|
| 59 |
+
os.chdir("..")
|
| 60 |
+
|
| 61 |
+
# Check again
|
| 62 |
+
missing_decoders = [f for f in decoder_files if not f.exists()]
|
| 63 |
+
if missing_decoders:
|
| 64 |
+
print(f"β Critical decoder files still missing: {[f.name for f in missing_decoders]}")
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
print("β
All critical model files verified present")
|
|
|
|
| 68 |
return True
|
| 69 |
+
|
| 70 |
+
finally:
|
| 71 |
+
os.chdir(original_cwd)
|
| 72 |
+
|
| 73 |
+
except subprocess.CalledProcessError as e:
|
| 74 |
+
print(f"β Git clone failed: {e}")
|
| 75 |
+
if e.stdout:
|
| 76 |
+
print(f"stdout: {e.stdout}")
|
| 77 |
+
if e.stderr:
|
| 78 |
+
print(f"stderr: {e.stderr}")
|
| 79 |
+
return False
|
| 80 |
+
|
| 81 |
+
except subprocess.TimeoutExpired:
|
| 82 |
+
print("β Git clone timed out (network issue or large repository)")
|
| 83 |
+
return False
|
| 84 |
+
|
| 85 |
+
except Exception as e:
|
| 86 |
+
print(f"β Unexpected error during download: {e}")
|
| 87 |
+
return False
|
| 88 |
|
| 89 |
|
| 90 |
def ensure_model_availability():
|
|
|
|
| 95 |
|
| 96 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 97 |
|
| 98 |
+
# Check if critical decoder files exist (these are the most important for vocoder)
|
| 99 |
+
critical_files = [
|
| 100 |
+
xcodec_base / "decoders" / "decoder_131000.pth",
|
| 101 |
+
xcodec_base / "decoders" / "decoder_151000.pth",
|
| 102 |
+
xcodec_base / "final_ckpt" / "ckpt_00360000.pth"
|
| 103 |
]
|
| 104 |
|
| 105 |
+
missing_files = [f for f in critical_files if not f.exists()]
|
| 106 |
|
| 107 |
if missing_files:
|
| 108 |
+
print(f"β οΈ Missing critical model files: {[f.name for f in missing_files]}")
|
| 109 |
+
print("π Starting model download with git clone...")
|
| 110 |
+
|
| 111 |
success = download_xcodec_models()
|
| 112 |
+
|
| 113 |
if success:
|
| 114 |
print("β
Model download completed successfully!")
|
| 115 |
else:
|
| 116 |
+
print("β Model download failed. Vocoder functionality will not work.")
|
| 117 |
return False
|
| 118 |
else:
|
| 119 |
+
print("β
All critical model files are already present")
|
| 120 |
|
| 121 |
return True
|
| 122 |
|