File size: 2,150 Bytes
da7ea76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd


def load_and_process_data(file_path):
    # Load the leaderboard data
    df = pd.read_pickle(file_path)

    # Group by 'lmm' and 'question' to calculate mean accuracy
    accuracy_df = (
        df.groupby(["lmm", "question"])["accepted_by_judge"].mean().reset_index()
    )
    accuracy_df = accuracy_df.rename(columns={"accepted_by_judge": "accuracy"})
    accuracy_df["accuracy"] = (accuracy_df["accuracy"] * 100).round(1)

    # Group by 'lmm' to calculate the count of images
    image_count_df = df.groupby("lmm")["image"].nunique().reset_index()
    image_count_df = image_count_df.rename(columns={"image": "Total Images"})

    return accuracy_df, image_count_df


def expand_and_format_df(accuracy_df, image_count_df):
    # Pivot and format the accuracy dataframe
    expanded_df = accuracy_df.pivot(index="lmm", columns="question", values="accuracy")
    expanded_df["Average"] = expanded_df.mean(axis=1).round(1)
    expanded_df = expanded_df.sort_values(by="Average", ascending=False).reset_index()
    expanded_df.columns.name = None

    # Merge the 'total_images' column
    final_df = pd.merge(expanded_df, image_count_df, on="lmm")

    return final_df.rename(columns={"lmm": "Model"})


def map_model_names(df, name_dict):
    # Map model names using the provided dictionary
    df["Model"] = df["Model"].map(name_dict)
    return df


# Dictionary for renaming models
name_dict = {
    "gpt4v": "GPT-4V(ision)",
    "llava": "LLaVA-1.5-13B",
    "llava-7b": "LLaVA-1.5-7B",
    "Long-SPHINX": "Long-SPHINX",
    "SPHINX": "SPHINX",
    "OtterHD": "OtterHD",
    "minigpt4v2": "MiniGPT4v2",
    "InstructBLIP-13B": "InstructBLIP-13B",
    "InstructBLIP": "InstructBLIP-7B",
    "qwen": "Qwen-VL-Chat",
    "fuyu-8b": "Fuyu-8B",
}

# Processing steps
accuracy_df, image_count_df = load_and_process_data("raw_outputs.pkl")
final_df = expand_and_format_df(accuracy_df, image_count_df)
final_df = map_model_names(final_df, name_dict)


# Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# GlitchBench Leaderboard")
    with gr.Row():
        gr.Dataframe(final_df)

demo.launch()