File size: 1,386 Bytes
6b85865
22725f7
 
ffdb8d3
3a8762c
6b85865
1b89da7
 
 
3a8762c
1b89da7
903d653
1b89da7
 
 
6b85865
1b89da7
 
 
ffdb8d3
1b89da7
 
903d653
1b89da7
 
df074bd
1b89da7
 
 
 
 
 
 
22725f7
cee6ea9
 
 
1b89da7
546eedf
 
22725f7
 
 
 
 
 
 
 
cee6ea9
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
import gradio as gr
import pandas as pd
import numpy as np
import json
import requests

# Read URLs from a file, one per line
with open('file_urls.txt', '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 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']]

def show_leaderboard():
    # Convert dataframe to html so that it can be displayed properly in Gradio
    return data.to_html()

iface = gr.Interface(fn=show_leaderboard, inputs=[], outputs="html")

# Run the interface. 
# Note: you don't need to use .launch() in Hugging Face Spaces, this is for local testing.
iface.launch()