AttrLLM / visualization /components /model_selector.py
Stephentao-30
Public Mode: default to BBQ Disambiguation / Perplexity / Word
fec89a2
"""
Gradio widget builders for the interpretability app.
This module provides small UI factory functions:
- create_model_selector: dropdown for selecting a model size/name.
- create_feature_level_selector: radio control for feature granularity (word/sentence/paragraph).
- create_attribution_method_toggle: radio control for attribution method.
"""
import gradio as gr
from typing import List
def create_model_selector() -> gr.Dropdown:
"""
Create a dropdown for model selection.
Usage:
models = list_models() # from loader/models.py (optional API)
"""
return gr.Dropdown(
choices=[
("Qwen3 4B Instruct", "small"),
("Mistral 7B Instruct v0.2", "medium"),
("Qwen3 30B Instruct", "large"),
],
value="small",
label="Model",
interactive=True,
elem_id="model-selector",
elem_classes=["bubble-select"],
)
def create_multimodal_model_selector() -> gr.Dropdown:
"""
Create a dropdown for multimodal (image-capable) model selection.
Keys must match loader/models_mm_vllm.py.
"""
return gr.Dropdown(
choices=["vl_small", "vl_large"],
value="vl_small",
label="Multimodal Model",
interactive=True,
elem_id="multimodal-model-selector",
)
def create_feature_level_selector(value: str = "sentence") -> gr.Radio:
"""Create the feature granularity selector."""
return gr.Radio(
choices=["word", "sentence", "paragraph"],
value=value,
label="Feature Level",
interactive=True,
)
def create_attribution_method_toggle(methods: List[str] | None = None) -> gr.Radio:
"""Create the attribution method toggle."""
choices = methods or ["shapley", "banzhaf", "influence"]
default_value = choices[0] if choices else "shapley"
return gr.Radio(
choices=choices,
value=default_value,
label="Attribution Method",
interactive=True,
)