Spaces:
Runtime error
Runtime error
File size: 2,182 Bytes
6b85865 3a8762c f9b88e9 88c2b27 f9b88e9 88c2b27 6b85865 88c2b27 3a8762c 88c2b27 903d653 6b85865 88c2b27 ffdb8d3 f9b88e9 903d653 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 |
import gradio as gr
import requests
import pandas as pd
import os
import fnmatch
import json
class MultiURLData:
def __init__(self, file_path):
self.file_path = file_path
def fetch_data(self):
dataframes = []
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
for filename in find_files('results', 'results*.json'):
model_name = filename.split('/')[2]
with open(filename) as f:
data = json.load(f)
df = pd.DataFrame(data['results']).T
# Rename 'acc' column to respective file names
df = df.rename(columns={'acc': model_name})
# Remove 'hendrycksTest-' from the index
df.index = df.index.str.replace('hendrycksTest-', '')
# Remove'harness|' from the index
df.index = df.index.str.replace('harness|', '')
dataframes.append(df[[model_name]]) # keep only the column of interest
# Merge the dataframes on index
data = pd.concat(dataframes, axis=1)
# Transpose the dataframe to swap rows and columns
data = data.transpose()
data['Model Name'] = data.index
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()
|