File size: 1,998 Bytes
3e72399 fec89a2 3e72399 fec89a2 3e72399 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """
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,
)
|