File size: 2,830 Bytes
2f2195a
54b2baf
e1a6930
cdeeed6
2f2195a
53d5dd8
d8f2ec7
54b2baf
1a7f19c
d8f2ec7
e1a6930
 
54b2baf
 
1a7f19c
54b2baf
 
 
 
 
 
 
 
 
 
e1a6930
53d5dd8
54b2baf
 
fbb8c61
e1a6930
1a7f19c
53d5dd8
 
 
 
 
 
60ded99
53d5dd8
60ded99
e1a6930
 
 
 
cca1790
 
 
 
 
 
 
7fa11aa
cca1790
 
 
 
 
 
 
 
 
 
fbb8c61
cca1790
60ded99
cca1790
 
 
 
 
 
 
60ded99
cca1790
 
60ded99
cca1790
 
b18c9e2
723cce8
cca1790
 
 
afa5fdc
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gradio as gr
import plotly.express as px
import numpy as np
from src.dataloading import get_leaderboard_models_cached, get_leaderboard_datasets

def create_heatmap(selected_models, selected_dataset):
    if not selected_models or not selected_dataset:
        return None  # Hide plot if inputs are missing

    # Generate random similarity matrix
    size = len(selected_models)
    similarities = np.random.rand(size, size)
    similarities = (similarities + similarities.T) / 2  # make symmetric
    similarities = np.round(similarities, 2)

    # Use Plotly Express imshow to create a heatmap
    fig = px.imshow(similarities,
                    x=selected_models,
                    y=selected_models,
                    color_continuous_scale='Viridis',
                    zmin=0, zmax=1,
                    text_auto=True)
    # Move x-axis labels to top and adjust tick angle for readability
    fig.update_xaxes(side="top", tickangle=45)
    # Update overall layout: title, dimensions, margins
    fig.update_layout(
        title=f"Similarity Matrix for {selected_dataset}",
        width=800 + 20 * size,
        height=800 + 20 * size,
        margin=dict(b=100, l=100)
    )
    return fig

def validate_inputs(selected_models, selected_dataset):
    if not selected_models:
        raise gr.Error("Please select at least one model!")
    if not selected_dataset:
        raise gr.Error("Please select a dataset!")
    

# Gradio interface setup
with gr.Blocks(title="LLM Similarity Analyzer") as demo:
    gr.Markdown("## Model Similarity Comparison Tool")
    
    with gr.Row():
        dataset_dropdown = gr.Dropdown(
            choices=get_leaderboard_datasets(),
            label="Select Dataset",
            filterable=True,
            interactive=True,
            info="Leaderboard benchmark datasets"
        )

        model_dropdown = gr.Dropdown(
            choices=get_leaderboard_models_cached(),
            label="Select Models",
            multiselect=True,
            filterable=True,
            allow_custom_value=False,
            info="Search and select multiple models"
        )
    
    generate_btn = gr.Button("Generate Heatmap", variant="primary")
    heatmap = gr.Plot(label="Similarity Heatmap", visible=True)
    
    # Use a single output (the figure)
    generate_btn.click(
        fn=validate_inputs,
        inputs=[model_dropdown, dataset_dropdown],
        queue=False
    ).then(
        fn=create_heatmap,
        inputs=[model_dropdown, dataset_dropdown],
        outputs=heatmap
    )
    
    # Clear button: clear selections and the plot
    clear_btn = gr.Button("Clear Selection")
    clear_btn.click(
        lambda: [None, None, None],
        outputs=[model_dropdown, dataset_dropdown, heatmap]
    )

if __name__ == "__main__":
    demo.launch()