Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,37 +43,56 @@ def filter_kwargs(cls, kwargs):
|
|
| 43 |
filtered_kwargs = {k: v for k, v in kwargs.items() if k in valid_params}
|
| 44 |
return filtered_kwargs
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def resolve_path(user_path, repo_root):
|
| 47 |
"""
|
| 48 |
-
|
| 49 |
-
1. 優先檢查本地路徑(絕對或相對)。
|
| 50 |
-
2. 如果找不到,則嘗試從 HF 快取目錄中尋找。
|
| 51 |
"""
|
| 52 |
-
#
|
| 53 |
if os.path.exists(user_path):
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
potential_repo_path = os.path.join(repo_root, user_path)
|
| 59 |
if os.path.exists(potential_repo_path):
|
| 60 |
print(f"在 Hugging Face 快取目錄中找到檔案: {potential_repo_path}")
|
| 61 |
return potential_repo_path
|
| 62 |
|
| 63 |
return None
|
|
|
|
| 64 |
|
| 65 |
def setup_models(repo_root, model_version):
|
| 66 |
"""載入所有必要的模型和設定"""
|
| 67 |
pretrained_model_name_or_path = os.path.join(repo_root, "Wan2.1-Fun-V1.1-1.3B-InP")
|
| 68 |
pretrained_wav2vec_path = os.path.join(repo_root, "wav2vec2-base-960h")
|
| 69 |
|
| 70 |
-
# <<< 核心修正:對設定檔使用與輸入檔案相同的路徑解析邏輯 >>>
|
| 71 |
config_relative_path = "deepspeed_config/wan2.1/wan_civitai.yaml"
|
| 72 |
config_path = resolve_path(config_relative_path, repo_root)
|
| 73 |
-
|
| 74 |
if not config_path:
|
| 75 |
-
raise FileNotFoundError(f"設定檔 '{config_relative_path}' 在當前目錄或 HF
|
| 76 |
-
# <<< 修正結束 >>>
|
| 77 |
|
| 78 |
print(f"正在從 {config_path} 載入設定...")
|
| 79 |
config = OmegaConf.load(config_path)
|
|
@@ -208,7 +227,6 @@ def main():
|
|
| 208 |
args = parser.parse_args()
|
| 209 |
|
| 210 |
print("--- 步驟 1: 正在檢查並下載模型與設定檔 ---")
|
| 211 |
-
# 確保所有需要的檔案都被下載,以作為本地找不到檔案時的後備
|
| 212 |
repo_root = snapshot_download(
|
| 213 |
repo_id="FrancisRing/StableAvatar",
|
| 214 |
allow_patterns=[
|
|
@@ -216,7 +234,7 @@ def main():
|
|
| 216 |
"Wan2.1-Fun-V1.1-1.3B-InP/*",
|
| 217 |
"wav2vec2-base-960h/*",
|
| 218 |
"deepspeed_config/**",
|
| 219 |
-
"example_case/**"
|
| 220 |
],
|
| 221 |
)
|
| 222 |
print("模型檔案已準備就緒。")
|
|
|
|
| 43 |
filtered_kwargs = {k: v for k, v in kwargs.items() if k in valid_params}
|
| 44 |
return filtered_kwargs
|
| 45 |
|
| 46 |
+
# <<< 核心修正:加入 Git LFS 指標檔的偵測與處理 >>>
|
| 47 |
+
def is_lfs_pointer(file_path):
|
| 48 |
+
"""檢查一個檔案是否為 Git LFS 指標檔。"""
|
| 49 |
+
try:
|
| 50 |
+
# 指標檔通常很小 (< 2KB)
|
| 51 |
+
if os.path.getsize(file_path) > 2048:
|
| 52 |
+
return False
|
| 53 |
+
with open(file_path, 'r') as f:
|
| 54 |
+
first_line = f.readline().strip()
|
| 55 |
+
# 指標檔的第一行通常是 'version https://git-lfs.github.com/spec/v1'
|
| 56 |
+
if 'git-lfs' in first_line:
|
| 57 |
+
return True
|
| 58 |
+
except (OSError, UnicodeDecodeError):
|
| 59 |
+
# 如果檔案無法讀取或不是文字檔,那它就不是指標檔
|
| 60 |
+
return False
|
| 61 |
+
return False
|
| 62 |
+
|
| 63 |
def resolve_path(user_path, repo_root):
|
| 64 |
"""
|
| 65 |
+
以正確的優先級解析檔案路徑,並處理 Git LFS 指標檔問題。
|
|
|
|
|
|
|
| 66 |
"""
|
| 67 |
+
# 檢查本地路徑是否存在
|
| 68 |
if os.path.exists(user_path):
|
| 69 |
+
# 檢查它是否為一個無效的 LFS 指標檔
|
| 70 |
+
if is_lfs_pointer(user_path):
|
| 71 |
+
print(f"警告:本地檔案 '{user_path}' 是一個 Git LFS 指標檔。將嘗試從 Hugging Face 快取中尋找完整檔案。")
|
| 72 |
+
# 如果是指標檔,則忽略它,並在下一步從 HF 快取中尋找
|
| 73 |
+
else:
|
| 74 |
+
# 如果是個正常檔案,直接使用
|
| 75 |
+
print(f"找到本地檔案: {os.path.abspath(user_path)}")
|
| 76 |
+
return os.path.abspath(user_path)
|
| 77 |
|
| 78 |
+
# 如果本地檔案不存在或是 LFS 指標檔,則從 HF 快取目錄中尋找
|
| 79 |
potential_repo_path = os.path.join(repo_root, user_path)
|
| 80 |
if os.path.exists(potential_repo_path):
|
| 81 |
print(f"在 Hugging Face 快取目錄中找到檔案: {potential_repo_path}")
|
| 82 |
return potential_repo_path
|
| 83 |
|
| 84 |
return None
|
| 85 |
+
# <<< 修正結束 >>>
|
| 86 |
|
| 87 |
def setup_models(repo_root, model_version):
|
| 88 |
"""載入所有必要的模型和設定"""
|
| 89 |
pretrained_model_name_or_path = os.path.join(repo_root, "Wan2.1-Fun-V1.1-1.3B-InP")
|
| 90 |
pretrained_wav2vec_path = os.path.join(repo_root, "wav2vec2-base-960h")
|
| 91 |
|
|
|
|
| 92 |
config_relative_path = "deepspeed_config/wan2.1/wan_civitai.yaml"
|
| 93 |
config_path = resolve_path(config_relative_path, repo_root)
|
|
|
|
| 94 |
if not config_path:
|
| 95 |
+
raise FileNotFoundError(f"設定檔 '{config_relative_path}' 在當前目錄或 HF 快取中都找不到。")
|
|
|
|
| 96 |
|
| 97 |
print(f"正在從 {config_path} 載入設定...")
|
| 98 |
config = OmegaConf.load(config_path)
|
|
|
|
| 227 |
args = parser.parse_args()
|
| 228 |
|
| 229 |
print("--- 步驟 1: 正在檢查並下載模型與設定檔 ---")
|
|
|
|
| 230 |
repo_root = snapshot_download(
|
| 231 |
repo_id="FrancisRing/StableAvatar",
|
| 232 |
allow_patterns=[
|
|
|
|
| 234 |
"Wan2.1-Fun-V1.1-1.3B-InP/*",
|
| 235 |
"wav2vec2-base-960h/*",
|
| 236 |
"deepspeed_config/**",
|
| 237 |
+
"example_case/**"
|
| 238 |
],
|
| 239 |
)
|
| 240 |
print("模型檔案已準備就緒。")
|