Spaces:
Sleeping
Sleeping
File size: 4,939 Bytes
810d25e a415f27 810d25e a415f27 810d25e a415f27 1596e83 a415f27 a085dc1 a415f27 810d25e a415f27 |
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space."""
import argparse
import gradio as gr
import numpy as np
import pandas as pd
import gradio as gr
import pandas as pd
from constants import BANNER, INTRODUCTION_TEXT, CITATION_TEXT, METRICS_TAB_TEXT, DIR_OUTPUT_REQUESTS
LAST_UPDATED = "Feb 27th 2024"
css = """
.markdown-text{font-size: 16pt}
th {
text-align: center;
}
td {
font-size: 16px; /* Adjust the font size as needed */
text-align: center;
}
"""
column_names = {
"model": "Model",
"Overall": "All π―",
"Turn 1": "Turn 1οΈβ£",
"Turn 2": "Turn 2οΈβ£",
}
model_info = {
"gpt-4": {"hf_name": "https://platform.openai.com/", "pretty_name": "gpt-4"},
"gpt-3.5-turbo": {"hf_name": "https://platform.openai.com/", "pretty_name": "gpt-3.5-turbo"},
"Llama-2-70b-hf": {"hf_name": "meta-llama/Llama-2-70b-hf", "pretty_name": "Llama-2-70B"},
"Llama-2-13b-hf": {"hf_name": "meta-llama/Llama-2-13b-hf", "pretty_name": "Llama-2-13B"},
"Llama-2-7b-hf": {"hf_name": "meta-llama/Llama-2-7b-hf", "pretty_name": "Llama-2-7B"},
"Mixtral-8x7B-v0.1": {"hf_name": "mistralai/Mixtral-8x7B-v0.1", "pretty_name": "Mixtral-8x7B"},
"Mistral-7b-v0.1": {"hf_name": "mistralai/Mistral-7B-v0.1", "pretty_name": "Mistral-7B"},
"Yi-34B": {"hf_name": "01-ai/Yi-34B", "pretty_name": "Yi-34B"},
"Yi-6B": {"hf_name": "01-ai/Yi-6B", "pretty_name": "Yi-6B"},
"gemma-7b": {"hf_name": "google/gemma-7b", "pretty_name": "Gemma-7B"},
"gemma-2b": {"hf_name": "google/gemma-2b", "pretty_name": "Gemma-2B"},
"phi-2": {"hf_name": "microsoft/phi-2", "pretty_name": "Phi-2 (2.7B)"},
"olmo": {"hf_name": "allenai/OLMo-7B", "pretty_name": "OLMo-7B"},
}
def make_clickable_model(model_name, model_info):
if model_info[model_name]['hf_name'].startswith("http"):
link = model_info[model_name]['hf_name']
else:
link = f"https://huggingface.co/{model_info[model_name]['hf_name']}"
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_info[model_name]["pretty_name"]}</a>'
def build_demo(original_df, TYPES):
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
# gr.HTML(BANNER, elem_id="banner")
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
# with gr.Tabs(elem_classes="tab-buttons") as tabs:
# with gr.TabItem("π
Leaderboard", elem_id="od-benchmark-tab-table", id=0):
leaderboard_table = gr.components.Dataframe(
value=original_df,
datatype=TYPES,
height=1000,
wrap=False,
elem_id="leaderboard-table",
interactive=False,
visible=True,
min_width=60,
)
# with gr.TabItem("π Metrics", elem_id="od-benchmark-tab-table", id=1):
# gr.Markdown(METRICS_TAB_TEXT, elem_classes="markdown-text")
gr.Markdown(f"Last updated on **{LAST_UPDATED}**", elem_classes="markdown-text")
with gr.Row():
with gr.Accordion("π Citation", open=False):
gr.Textbox(
value=CITATION_TEXT, lines=7,
label="Copy the BibTeX to cite URIAL and MT-Bench",
elem_id="citation-button",
show_copy_button=True)
# ).style(show_copy_button=True)
return demo
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--share", action="store_true")
parser.add_argument("--result_file", help="Path to results table", default="leaderboard_data.jsonl")
args = parser.parse_args()
bench_results = args.result_file
original_df = pd.read_json(bench_results, lines=True)
print(original_df.columns)
for col in original_df.columns:
if col == "model":
original_df[col] = original_df[col].apply(lambda x: x.replace(x, make_clickable_model(x, model_info)))
else:
pass
# original_df[col] = original_df[col].apply(formatter) # For numerical values
# Define the first column explicitly, add 'Overall' as the second column, and then append the rest excluding 'Overall'
new_order = [original_df.columns[0], 'Overall'] + [col for col in original_df.columns if col not in [original_df.columns[0], 'Overall']]
# Reorder the DataFrame columns using the new order
reordered_df = original_df[new_order]
reordered_df.sort_values(by='Overall', inplace=True, ascending=False)
reordered_df.rename(columns=column_names, inplace=True)
# COLS = [c.name for c in fields(AutoEvalColumn)]
# TYPES = [c.type for c in fields(AutoEvalColumn)]
TYPES = ["markdown", "number"]
demo = build_demo(reordered_df, TYPES)
demo.launch(share=args.share)
|