获取 LoRA 模型可选项,从 model_path/loras 目录检索 Args: model_path: 模型根路径 Returns: list: LoRA 文件列表,如果没有则返回 [""]
(model_path)
| 30 | |
| 31 | |
| 32 | def get_lora_choices(model_path): |
| 33 | """获取 LoRA 模型可选项,从 model_path/loras 目录检索 |
| 34 | |
| 35 | Args: |
| 36 | model_path: 模型根路径 |
| 37 | |
| 38 | Returns: |
| 39 | list: LoRA 文件列表,如果没有则返回 [""] |
| 40 | """ |
| 41 | loras_dir = os.path.join(model_path, "loras") |
| 42 | if not os.path.exists(loras_dir): |
| 43 | return [""] |
| 44 | |
| 45 | lora_files = [] |
| 46 | # 支持常见的 LoRA 文件格式 |
| 47 | lora_extensions = [".safetensors", ".pt", ".pth", ".ckpt"] |
| 48 | |
| 49 | for item in os.listdir(loras_dir): |
| 50 | item_path = os.path.join(loras_dir, item) |
| 51 | if os.path.isfile(item_path): |
| 52 | # 检查是否是 LoRA 文件 |
| 53 | if any(item.lower().endswith(ext) for ext in lora_extensions): |
| 54 | lora_files.append(item) |
| 55 | |
| 56 | # 按文件名排序 |
| 57 | lora_files.sort() |
| 58 | |
| 59 | return lora_files if lora_files else [""] |
| 60 | |
| 61 | |
| 62 | def build_wan21_components(model_path, model_path_input, model_type_input, task_type_input, download_source_input, update_funcs, download_funcs, lang="zh"): |
no test coverage detected