Spaces:
Runtime error
Runtime error
File size: 1,984 Bytes
6c46ed2 cd2dfb2 6c46ed2 cd2dfb2 6c46ed2 cd2dfb2 6c46ed2 cd2dfb2 6c46ed2 cd2dfb2 6c46ed2 |
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 |
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-', '')
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)
# 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']]
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()
|