Bugfix
Browse files
app.py
CHANGED
|
@@ -2,12 +2,44 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Read the CSV file
|
| 6 |
df = pd.read_csv('passk.csv')
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Create a dictionary to map models to friendly names
|
| 13 |
model_to_friendly = {
|
|
@@ -20,35 +52,53 @@ def get_friendly_name(model):
|
|
| 20 |
return model_to_friendly.get(model, model)
|
| 21 |
|
| 22 |
# Create a pivot table
|
| 23 |
-
pivot = df.pivot(index='
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Function to update the table based on selected languages
|
| 28 |
def update_table(selected_languages):
|
| 29 |
if not selected_languages:
|
| 30 |
-
return
|
| 31 |
|
| 32 |
display_data = pivot[selected_languages].replace(np.nan, "-")
|
| 33 |
display_data = display_data.applymap(lambda x: f"{x:.3f}" if isinstance(x, (int, float)) else x)
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Create the Gradio interface
|
| 38 |
with gr.Blocks() as app:
|
| 39 |
gr.Markdown("# Model Leaderboard")
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
-
language_checkboxes = gr.CheckboxGroup(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
table = gr.Dataframe(
|
| 45 |
-
headers=[
|
| 46 |
-
|
| 47 |
-
col_count=(lambda: len(languages)),
|
| 48 |
-
interactive=False
|
| 49 |
)
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Launch the app
|
| 54 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
# Dictionary mapping file extensions to full language names
|
| 6 |
+
extension_to_language = {
|
| 7 |
+
"clj": "Clojure",
|
| 8 |
+
"cpp": "C++",
|
| 9 |
+
"cs": "C#",
|
| 10 |
+
"d": "D",
|
| 11 |
+
"elixir": "Elixir",
|
| 12 |
+
"go": "Go",
|
| 13 |
+
"hs": "Haskell",
|
| 14 |
+
"java": "Java",
|
| 15 |
+
"jl": "Julia",
|
| 16 |
+
"js": "JavaScript",
|
| 17 |
+
"lua": "Lua",
|
| 18 |
+
"ml": "OCaml",
|
| 19 |
+
"php": "PHP",
|
| 20 |
+
"pl": "Perl",
|
| 21 |
+
"r": "R",
|
| 22 |
+
"rb": "Ruby",
|
| 23 |
+
"rkt": "Racket",
|
| 24 |
+
"rs": "Rust",
|
| 25 |
+
"scala": "Scala",
|
| 26 |
+
"sh": "Shell",
|
| 27 |
+
"swift": "Swift",
|
| 28 |
+
"ts": "TypeScript"
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
# Read the CSV file
|
| 32 |
df = pd.read_csv('passk.csv')
|
| 33 |
|
| 34 |
+
# Function to extract language and model from Dataset
|
| 35 |
+
def extract_info(dataset):
|
| 36 |
+
parts = dataset.split('-')
|
| 37 |
+
language = parts[1]
|
| 38 |
+
model = '-'.join(parts[2:-2])
|
| 39 |
+
return pd.Series({'Language': language, 'Model': model})
|
| 40 |
+
|
| 41 |
+
# Extract language and model information
|
| 42 |
+
df[['Language', 'Model']] = df['Dataset'].apply(extract_info)
|
| 43 |
|
| 44 |
# Create a dictionary to map models to friendly names
|
| 45 |
model_to_friendly = {
|
|
|
|
| 52 |
return model_to_friendly.get(model, model)
|
| 53 |
|
| 54 |
# Create a pivot table
|
| 55 |
+
pivot = df.pivot(index='Model', columns='Language', values='Estimate')
|
| 56 |
+
|
| 57 |
+
# Get unique languages and models
|
| 58 |
+
languages = sorted(pivot.columns)
|
| 59 |
+
models = sorted(pivot.index)
|
| 60 |
|
| 61 |
# Function to update the table based on selected languages
|
| 62 |
def update_table(selected_languages):
|
| 63 |
if not selected_languages:
|
| 64 |
+
return pd.DataFrame({'Model': [get_friendly_name(model) for model in models]})
|
| 65 |
|
| 66 |
display_data = pivot[selected_languages].replace(np.nan, "-")
|
| 67 |
display_data = display_data.applymap(lambda x: f"{x:.3f}" if isinstance(x, (int, float)) else x)
|
| 68 |
+
|
| 69 |
+
# Add the Model column as the first column
|
| 70 |
+
display_data.insert(0, 'Model', [get_friendly_name(model) for model in display_data.index])
|
| 71 |
+
|
| 72 |
+
# Reset the index to remove the model names from the index
|
| 73 |
+
display_data = display_data.reset_index(drop=True)
|
| 74 |
+
|
| 75 |
+
# Rename columns to full language names
|
| 76 |
+
display_data.columns = ['Model'] + [extension_to_language.get(lang, lang) for lang in selected_languages]
|
| 77 |
+
|
| 78 |
+
return display_data
|
| 79 |
|
| 80 |
# Create the Gradio interface
|
| 81 |
with gr.Blocks() as app:
|
| 82 |
gr.Markdown("# Model Leaderboard")
|
| 83 |
|
| 84 |
with gr.Row():
|
| 85 |
+
language_checkboxes = gr.CheckboxGroup(
|
| 86 |
+
choices=[f"{extension_to_language[lang]} ({lang})" for lang in languages],
|
| 87 |
+
label="Select Languages",
|
| 88 |
+
value=[f"{extension_to_language[lang]} ({lang})" for lang in languages]
|
| 89 |
+
)
|
| 90 |
|
| 91 |
table = gr.Dataframe(
|
| 92 |
+
headers=['Model'] + [extension_to_language.get(lang, lang) for lang in languages],
|
| 93 |
+
type="pandas"
|
|
|
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
+
def update_table_wrapper(selected_languages):
|
| 97 |
+
# Extract language codes from the selected full names
|
| 98 |
+
selected_codes = [lang.split('(')[-1].strip(')') for lang in selected_languages]
|
| 99 |
+
return update_table(selected_codes)
|
| 100 |
+
|
| 101 |
+
language_checkboxes.change(update_table_wrapper, inputs=[language_checkboxes], outputs=[table])
|
| 102 |
|
| 103 |
# Launch the app
|
| 104 |
if __name__ == "__main__":
|