Spaces:
Runtime error
Runtime error
File size: 2,320 Bytes
6b85865 3a8762c f9b88e9 6b85865 f9b88e9 3a8762c f9b88e9 903d653 f9b88e9 6b85865 f9b88e9 ffdb8d3 f9b88e9 903d653 f9b88e9 df074bd f9b88e9 1b89da7 f9b88e9 1b89da7 f9b88e9 22725f7 f9b88e9 cee6ea9 f9b88e9 546eedf f9b88e9 22725f7 f9b88e9 22725f7 f9b88e9 |
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 |
import gradio as gr
import requests
import pandas as pd
class MultiURLData:
def __init__(self, file_path):
self.file_path = file_path
def fetch_data(self):
# Read URLs from a file, one per line
with open(self.file_path, 'r') as f:
file_urls = [line.strip() for line in f.readlines()]
dataframes = []
for url in file_urls:
# Derive column names from the URLs
column_name = url.split('/')[-1].split('_')[0]
# Load data from URL
response = requests.get(url)
data = response.json()
# Convert data into a DataFrame
df = pd.DataFrame(data['results']).T
# Rename 'acc' column to respective file names
df = df.rename(columns={'acc': column_name})
# Remove 'hendrycksTest-' from the index
df.index = df.index.str.replace('hendrycksTest-', '')
print(f"dype df {type(df)}")
dataframes.append(df[[column_name]]) # keep only the column of interest
# Merge the dataframes
# Merge the dataframes on index
data = pd.concat(dataframes, axis=1)
print(f"dype data {type(data)}")
# Transpose the dataframe to swap rows and columns
data = data.transpose()
# Select only columns 'moral_scenarios' and 'moral_disputes'
data = data[['moral_scenarios', 'moral_disputes']]
## add a column with the index of the dataframe
data['Model Name'] = data.index
# move the column to the front of the dataframe
cols = data.columns.tolist()
cols = cols[-1:] + cols[:-1]
data = data[cols]
return data
data_provider = MultiURLData("file_urls.txt")
block = gr.Blocks()
with block:
gr.Markdown("""Leaderboard""")
with gr.Tabs():
with gr.TabItem("Leaderboard"):
with gr.Row():
data = gr.outputs.Dataframe(type="pandas")
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(data_provider.fetch_data, inputs=None, outputs=data)
# running the function on page load in addition to when the button is clicked
block.load(data_provider.fetch_data, inputs=None, outputs=data)
block.launch()
|