Spaces:
Sleeping
Sleeping
File size: 3,475 Bytes
35080ea a5e4fec 35080ea a5e4fec 35080ea | 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 | import gradio as gr
import pandas as pd
import json
def process_df(df):
# Set the current date and time
df['date'] = pd.Timestamp.now().strftime('%Y-%m-%d %H:%M')
# Create clickable links in the "Model" column
df['Model'] = df.apply(lambda x: f'<a href="{x["Link"]}" target="_blank">{x["Model"]}</a>', axis=1)
# Drop the "Link" column
df = df.drop(['Link'], axis=1)
# Convert columns to float
cols = df.columns.drop(['Model', 'date'])
df[cols] = df[cols].astype(float)
# Highlight the minimum values in the columns
styled_df = df.style.highlight_min(color='lightgreen', axis=0, subset=cols)
return styled_df
def get_eval(jsonfile):
global leaderboard_df
# Load JSON data
data = json.load(open(jsonfile))
# Convert JSON data to DataFrame
df = pd.DataFrame.from_dict(data, orient='columns')
# Concatenate with the existing leaderboard
leaderboard_df = pd.concat([leaderboard_df, df], ignore_index=True)
# Process the dataframe
df = process_df(leaderboard_df)
return df
def refresh_leaderboard():
global leaderboard_df
if len(leaderboard_df) == 0:
return leaderboard_df
else:
return process_df(leaderboard_df)
# Usage markdown
usage = """
## Using the web interface
Run your model on the evaluation datasets and create a json file in this format:
```
[
{
"Model": "whisperbase",
"date": "",
"ucfd_eng": 102.27,
"ucfd_lug": "nan",
"sema_eng" : 42.86,
"sema_lug": "nan",
"trac_fm_lug": "nan",
"Link": "https://colab.research.google.com/drive/1MGGOotrjSXWkR3ljNEVvfEUResEx6OLV#scrollTo=Elwx1K3fEDjf"
},
{
"Model": "facebookmms",
"date": "2024-06-26",
"ucfd_eng": 92.91,
"ucfd_lug": "nan",
"sema_eng" : 63.39,
"sema_lug": "nan",
"trac_fm_lug": 69.29,
"Link": "https://colab.research.google.com/drive/1MGGOotrjSXWkR3ljNEVvfEUResEx6OLV#scrollTo=Elwx1K3fEDjf"
}
]
```
>Upload this to the leaderboard and it should be updated with your results.
## Using the API
You can use the following code to programmatically upload your results from a colab or python script.
```
from gradio_client import Client, handle_file
client = Client("sunbird/SB_ASR_Leaderboard")
result = client.predict(
jsonfile=handle_file([/path/to/eval_results.json]),
api_name="/get_eval"
)
```
>Refresh the leaderboard and your results should be visible.
"""
# Initialize an empty dataframe for the leaderboard
columns = ['Model', 'date', 'ucfd_eng', 'ucfd_lug',
'sema_eng', 'sema_lug', 'trac_fm_lug']
leaderboard_df = pd.DataFrame(columns=columns)
# Create Gradio interface
block = gr.Blocks()
with block:
gr.Markdown("## Leaderboard for Sunbird AI ASR")
with gr.Row():
input_json = gr.UploadButton("Upload a JSON file", file_count="single", scale=0)
with gr.Tabs():
with gr.TabItem("ASR Leaderboard"):
with gr.Row():
data = gr.DataFrame(datatype="markdown")
with gr.TabItem("Usage"):
with gr.Row():
gr.Markdown(usage)
input_json.upload(get_eval, inputs=input_json, outputs=data)
# Running the function on page load in addition to when the button is clicked
block.load(refresh_leaderboard, inputs=None, outputs=data)
block.launch(share=True) |