From ef31ce70c7cc20ef2beae3345a57cfc6d6fff275 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Sun, 13 Sep 2026 22:59:32 +0100 Subject: [PATCH] refactor(civitai): seed the base-model filter from discovery only search_civitai.base_models was a hand-kept copy of the /enums list that lacked every base added this year. The dropdown starts empty and takes the discovered names minus the bases CivitAI has retired (in BaseModel but not ActiveBaseModel). The tab handler refreshes the choice lists on every visit, since later browser sessions used to get no update; the initial search still runs once per process. --- modules/civitai/search_civitai.py | 4 ---- modules/ui_models.py | 15 ++++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/civitai/search_civitai.py b/modules/civitai/search_civitai.py index 6c4fd99dc..aea995628 100644 --- a/modules/civitai/search_civitai.py +++ b/modules/civitai/search_civitai.py @@ -5,10 +5,6 @@ from modules.civitai.client_civitai import client from modules.civitai.models_civitai import CivitModel, CivitSearchResponse -# Hardcoded fallback list — used by Gradio UI if discover_options() fails -base_models = ['', 'AuraFlow', 'Chroma', 'CogVideoX', 'Flux.1 S', 'Flux.1 D', 'Flux.1 Krea', 'Flux.1 Kontext', 'Flux.2 D', 'HiDream', 'Hunyuan 1', 'Hunyuan Video', 'Illustrious', 'Kolors', 'LTXV', 'Lumina', 'Mochi', 'NoobAI', 'PixArt a', 'PixArt E', 'Pony', 'Pony V7', 'Qwen', 'SD 1.4', 'SD 1.5', 'SD 1.5 LCM', 'SD 1.5 Hyper', 'SD 2.0', 'SD 2.1', 'SDXL 1.0', 'SDXL Lightning', 'SDXL Hyper', 'Wan Video 1.3B t2v', 'Wan Video 14B t2v', 'Wan Video 14B i2v 480p', 'Wan Video 14B i2v 720p', 'Wan Video 2.2 TI2V-5B', 'Wan Video 2.2 I2V-A14B', 'Wan Video 2.2 T2V-A14B', 'Wan Video 2.5 T2V', 'Wan Video 2.5 I2V', 'ZImageTurbo', 'Other'] - - def search_civitai( query: str, tag: str = '', diff --git a/modules/ui_models.py b/modules/ui_models.py index b3b4b6839..1aab89bba 100644 --- a/modules/ui_models.py +++ b/modules/ui_models.py @@ -521,7 +521,7 @@ def create_ui(): ) with gr.Tab(label="CivitAI", elem_id="models_civitai_tab") as civitai_tab: - from modules.civitai.search_civitai import search_civitai, create_model_cards, base_models + from modules.civitai.search_civitai import search_civitai, create_model_cards sort_fallback = ['', 'Most Downloaded', 'Highest Rated', 'Most Liked', 'Most Discussed', 'Most Collected', 'Most Images', 'Newest', 'Oldest'] @@ -572,7 +572,7 @@ def create_ui(): civit_download_btn = gr.Button(value="Download model", variant='primary', elem_id="civitai_download_btn", visible=False) with gr.Row(): civit_type = gr.Dropdown(choices=type_fallback, label='CivitAI model type', value='', elem_id='civit_type') - civit_base = gr.Dropdown(choices=base_models, label='CivitAI base model', value='') + civit_base = gr.Dropdown(choices=[''], label='CivitAI base model', value='') with gr.Row(): civit_sort = gr.Dropdown(choices=sort_fallback, label='CivitAI sort', value='', elem_id='civit_sort') civit_period = gr.Dropdown( @@ -628,14 +628,15 @@ def create_ui(): def civitai_on_tab_enter(): nonlocal _civitai_loaded - if _civitai_loaded: - return [gr.update(), gr.update(), gr.update(), gr.update(), gr.update()] - _civitai_loaded = True from modules.civitai.client_civitai import client - options = client.discover_options() + options = client.discover_options() # cached, so every visit can refresh the choices type_choices = [''] + (options.get('types', []) or type_fallback[1:]) sort_choices = [''] + (options.get('sort', []) or sort_fallback[1:]) - base_choices = [''] + (options.get('base_models', []) or base_models[1:]) + hidden_bases = {entry.get('name') for entry in options.get('base_models_info', []) if entry.get('hidden')} # retired bases, which the site's own filter omits too + base_choices = [''] + [base for base in options.get('base_models', []) if base not in hidden_bases] + if _civitai_loaded: + return [gr.update(choices=type_choices), gr.update(choices=sort_choices), gr.update(choices=base_choices), gr.update(), gr.update()] + _civitai_loaded = True results = search_civitai(query='', sort='Most Downloaded', period='AllTime', limit=20) html = create_model_cards(results) return [