fix: 标签文件下载失败时给出明确错误提示
This commit is contained in:
@@ -140,8 +140,9 @@ def _ensure_model(model_dir):
|
|||||||
_download_file(HF_TAGS_URL, tags_path)
|
_download_file(HF_TAGS_URL, tags_path)
|
||||||
print("=== 标签文件下载完成", flush=True)
|
print("=== 标签文件下载完成", flush=True)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print("=== 标签文件下载失败: %s" % exc, flush=True)
|
# 标签文件下载失败不影响模型运行,只是无法解析输出标签
|
||||||
return None, None
|
print("=== 警告: 标签文件下载失败,将无法解析输出标签: %s" % exc, flush=True)
|
||||||
|
tags_path = "" # 标记标签文件不可用,但仍返回模型路径
|
||||||
|
|
||||||
return model_path, tags_path
|
return model_path, tags_path
|
||||||
|
|
||||||
@@ -180,6 +181,10 @@ def get_session():
|
|||||||
global _session
|
global _session
|
||||||
if "_session" not in dir() or _session is None:
|
if "_session" not in dir() or _session is None:
|
||||||
model_path, tags_path = _ensure_model(MODEL_DIR)
|
model_path, tags_path = _ensure_model(MODEL_DIR)
|
||||||
|
if not model_path:
|
||||||
|
raise RuntimeError("wd-tagger 模型不可用")
|
||||||
|
if not tags_path:
|
||||||
|
raise RuntimeError("wd-tagger 标签文件不可用,无法解析输出。请手动下载 %s 到 %s" % (TAGS_FILENAME, os.path.join(MODEL_DIR, MODEL_DIR_NAME)))
|
||||||
_load_tags(tags_path)
|
_load_tags(tags_path)
|
||||||
_session = _new_session(model_path)
|
_session = _new_session(model_path)
|
||||||
return _session
|
return _session
|
||||||
|
|||||||
Reference in New Issue
Block a user