ling-series-spaces / ui_components /model_selector.py
GitHub Action
Sync ling-space changes (filtered) from commit 127300e
b931367
raw
history blame
1.37 kB
import gradio as gr
def create_model_selector(model_specs, default_model_constant):
"""
Creates a reusable Gradio model selector component.
Args:
model_specs (dict): A dictionary containing the specifications for each model.
default_model_constant (str): The key for the default model in the model_specs dictionary.
Returns:
tuple: A tuple containing the model dropdown and the model description markdown components.
"""
display_names = [d["display_name"] for d in model_specs.values()]
default_display_name = model_specs[default_model_constant]["display_name"]
model_dropdown = gr.Dropdown(
choices=display_names,
label="ζ¨‘εž‹ι€‰ζ‹©",
value=default_display_name,
interactive=True
)
def get_model_description(model_display_name):
for model_spec in model_specs.values():
if model_spec["display_name"] == model_display_name:
return model_spec["description"]
return ""
model_description_markdown = gr.Markdown(get_model_description(default_display_name),
container=True)
model_dropdown.change(
fn=get_model_description,
inputs=[model_dropdown],
outputs=[model_description_markdown]
)
return model_dropdown, model_description_markdown