构建 Qwen-Image-Edit-2511/Qwen-Image-2512 模型相关组件(用于图片页面) 必须在 Gradio 的 with 块内调用 Args: model_path: 模型路径 model_path_input: 模型路径输入组件 download_source_input: 下载源输入组件 model_type_input: 模型类型输入组件(用于动态更新) lang: 语言代码,默认为 "zh" Returns: dict: 包含所有 Qwen
(model_path, model_path_input, download_source_input, model_type_input, lang="zh")
| 337 | |
| 338 | |
| 339 | def build_qwen_image_components(model_path, model_path_input, download_source_input, model_type_input, lang="zh"): |
| 340 | """构建 Qwen-Image-Edit-2511/Qwen-Image-2512 模型相关组件(用于图片页面) |
| 341 | 必须在 Gradio 的 with 块内调用 |
| 342 | |
| 343 | Args: |
| 344 | model_path: 模型路径 |
| 345 | model_path_input: 模型路径输入组件 |
| 346 | download_source_input: 下载源输入组件 |
| 347 | model_type_input: 模型类型输入组件(用于动态更新) |
| 348 | lang: 语言代码,默认为 "zh" |
| 349 | |
| 350 | Returns: |
| 351 | dict: 包含所有 Qwen-Image 相关组件的字典 |
| 352 | """ |
| 353 | |
| 354 | # 根据模型类型选择函数 |
| 355 | def get_dit_choices_func(model_path_val): |
| 356 | model_type_val = model_type_input.value if hasattr(model_type_input, "value") else "Qwen-Image-Edit-2511" |
| 357 | if model_type_val == "Qwen-Image-2512": |
| 358 | return get_qwen_image_2512_dit_choices(model_path_val) |
| 359 | else: |
| 360 | return get_qwen_image_dit_choices(model_path_val) |
| 361 | |
| 362 | def get_vae_choices_func(model_path_val): |
| 363 | model_type_val = model_type_input.value if hasattr(model_type_input, "value") else "Qwen-Image-Edit-2511" |
| 364 | if model_type_val == "Qwen-Image-2512": |
| 365 | return get_qwen_image_2512_vae_choices(model_path_val) |
| 366 | else: |
| 367 | return get_qwen_image_vae_choices(model_path_val) |
| 368 | |
| 369 | def get_scheduler_choices_func(model_path_val): |
| 370 | model_type_val = model_type_input.value if hasattr(model_type_input, "value") else "Qwen-Image-Edit-2511" |
| 371 | if model_type_val == "Qwen-Image-2512": |
| 372 | return get_qwen_image_2512_scheduler_choices(model_path_val) |
| 373 | else: |
| 374 | return get_qwen_image_scheduler_choices(model_path_val) |
| 375 | |
| 376 | qwen_image_dit_choices_init = get_dit_choices_func(model_path) |
| 377 | qwen_image_vae_choices_init = get_vae_choices_func(model_path) |
| 378 | qwen_image_scheduler_choices_init = get_scheduler_choices_func(model_path) |
| 379 | |
| 380 | # 初始化时检查模型状态,确定下载按钮的初始可见性 |
| 381 | def get_initial_download_btn_visibility(choices, model_path_val, model_type_val, base_category): |
| 382 | if not choices: |
| 383 | return False |
| 384 | first_choice = choices[0] |
| 385 | from utils.model_utils import check_model_exists, extract_model_name |
| 386 | |
| 387 | actual_name = extract_model_name(first_choice) |
| 388 | exists = check_model_exists(model_path_val, actual_name) |
| 389 | return not exists |
| 390 | |
| 391 | initial_model_type = model_type_input.value if hasattr(model_type_input, "value") else "Qwen-Image-Edit-2511" |
| 392 | dit_btn_visible = get_initial_download_btn_visibility(qwen_image_dit_choices_init, model_path, initial_model_type, "dit") |
| 393 | vae_btn_visible = get_initial_download_btn_visibility(qwen_image_vae_choices_init, model_path, initial_model_type, "vae") |
| 394 | scheduler_btn_visible = get_initial_download_btn_visibility(qwen_image_scheduler_choices_init, model_path, initial_model_type, "scheduler") |
| 395 | |
| 396 | # Qwen-Image 模型配置 |
no test coverage detected