处理文件列表,提取模型名称
(files, repo_id=None)
| 199 | |
| 200 | |
| 201 | def process_files(files, repo_id=None): |
| 202 | """处理文件列表,提取模型名称""" |
| 203 | model_names = [] |
| 204 | seen_dirs = set() |
| 205 | |
| 206 | # 对于 Qwen/Qwen-Image-Edit-2511、Qwen/Qwen-Image-2512 和 Tongyi-MAI/Z-Image-Turbo 仓库,保留 vae 和 scheduler 目录 |
| 207 | is_qwen_image_repo = repo_id in ["Qwen/Qwen-Image-Edit-2511", "Qwen/Qwen-Image-2512", "Tongyi-MAI/Z-Image-Turbo"] |
| 208 | # 对于 Qwen3 编码器仓库,整个仓库就是一个模型目录 |
| 209 | is_qwen3_encoder_repo = repo_id == "JunHowie/Qwen3-4B-GPTQ-Int4" |
| 210 | |
| 211 | for file in files: |
| 212 | # 排除包含comfyui的文件 |
| 213 | if "comfyui" in file.lower(): |
| 214 | continue |
| 215 | |
| 216 | # 如果是顶层文件(不包含路径分隔符) |
| 217 | if "/" not in file: |
| 218 | # 对于 Qwen3 编码器仓库,不添加单个文件,只添加目录 |
| 219 | # 因为 Qwen3 编码器应该下载整个仓库目录 |
| 220 | if not is_qwen3_encoder_repo and file.endswith(".safetensors"): |
| 221 | model_names.append(file) |
| 222 | else: |
| 223 | # 提取顶层目录名(支持_split目录) |
| 224 | top_dir = file.split("/")[0] |
| 225 | if top_dir not in seen_dirs: |
| 226 | seen_dirs.add(top_dir) |
| 227 | # 对于 Qwen 仓库,保留 vae 和 scheduler 目录 |
| 228 | if is_qwen_image_repo and top_dir.lower() in ["vae", "scheduler"]: |
| 229 | model_names.append(top_dir) |
| 230 | # 对于 Qwen3 编码器仓库,保留所有顶层目录(排除 comfyui) |
| 231 | elif is_qwen3_encoder_repo: |
| 232 | model_names.append(top_dir) |
| 233 | # 支持safetensors文件目录和_split分block存储目录 |
| 234 | elif "_split" in top_dir or any(f.startswith(f"{top_dir}/") and f.endswith(".safetensors") for f in files): |
| 235 | model_names.append(top_dir) |
| 236 | return sorted(set(model_names)) |
| 237 | |
| 238 | |
| 239 | def load_hf_models_cache(): |
no test coverage detected