检查模型是否已下载 支持子目录路径,如 Qwen-Image-2512/qwen_image_2512_fp8_e4m3fn_scaled.safetensors
(model_path, model_name)
| 338 | |
| 339 | |
| 340 | def check_model_exists(model_path, model_name): |
| 341 | """检查模型是否已下载 |
| 342 | 支持子目录路径,如 Qwen-Image-2512/qwen_image_2512_fp8_e4m3fn_scaled.safetensors |
| 343 | """ |
| 344 | if not model_path or not os.path.exists(model_path): |
| 345 | return False |
| 346 | |
| 347 | # 处理包含子目录路径的模型名(如 Qwen-Image-2512/qwen_image_2512_fp8_e4m3fn_scaled.safetensors) |
| 348 | model_path_full = os.path.join(model_path, model_name) |
| 349 | # 检查是否存在(文件或目录) |
| 350 | if os.path.exists(model_path_full): |
| 351 | return True |
| 352 | |
| 353 | # 额外检查:如果是 safetensors 文件,也检查同名目录(_split 目录) |
| 354 | if model_name.endswith(".safetensors"): |
| 355 | # 如果模型名包含子目录路径,提取文件名 |
| 356 | if "/" in model_name: |
| 357 | base_name_with_subdir = model_name.replace(".safetensors", "") |
| 358 | # 检查子目录下的 _split 目录 |
| 359 | split_dir = os.path.join(model_path, base_name_with_subdir + "_split") |
| 360 | if os.path.exists(split_dir): |
| 361 | return True |
| 362 | else: |
| 363 | # 检查同名目录(可能是分块存储) |
| 364 | base_name = model_name.replace(".safetensors", "") |
| 365 | split_dir = os.path.join(model_path, base_name + "_split") |
| 366 | if os.path.exists(split_dir): |
| 367 | return True |
| 368 | |
| 369 | return False |
| 370 | |
| 371 | |
| 372 | def format_model_choice(model_name, model_path, status_emoji=None): |
no outgoing calls
no test coverage detected