Spaces:
Running
Running
import os | |
import json | |
import pandas as pd | |
def model_hyperlink(model_link, model): | |
return f'<a target="_blank" href="{model_link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model}</a>' | |
def load_all_data(data_dir): | |
data_list = [] | |
# Traverse the directory to find all JSON files | |
for root, dirs, files in os.walk(data_dir): | |
for file in files: | |
if file.endswith('.json'): | |
file_path = os.path.join(root, file) | |
# Load JSON data | |
with open(file_path, 'r', encoding='utf-8') as f: | |
data = json.load(f) | |
# Extract relevant data | |
model = data.get("model", "") | |
model_link = data.get("model_link", "") | |
with_tie = data.get("with_tie", {}) | |
without_tie = data.get("without_tie", {}) | |
# Calculate averages | |
avg_with_tie = round(sum(with_tie.values()) / len(with_tie), 2) if with_tie else 0 | |
avg_without_tie = round(sum(without_tie.values()) / len(without_tie), 2) if without_tie else 0 | |
avg = round((avg_with_tie + avg_without_tie) / 2, 2) | |
# Append to list | |
data_list.append({ | |
"Model": model_hyperlink(model_link, model), | |
"Model Type": data.get("model_type", ""), | |
"Avg.": avg, | |
"Avg. (w/o Ties)": avg_without_tie, | |
"Avg. (w/ Ties)": avg_with_tie, | |
"Overall (w/o Ties)": round(without_tie.get("overall", 0), 2), | |
"VQ (w/o Ties)": round(without_tie.get("vq", 0), 2), | |
"MQ (w/o Ties)": round(without_tie.get("mq", 0), 2), | |
"TA (w/o Ties)": round(without_tie.get("ta", 0), 2), | |
"Overall (w/ Ties)": round(with_tie.get("overall", 0), 2), | |
"VQ (w/ Ties)": round(with_tie.get("vq", 0), 2), | |
"MQ (w/ Ties)": round(with_tie.get("mq", 0), 2), | |
"TA (w/ Ties)": round(with_tie.get("ta", 0), 2), | |
}) | |
# Create a DataFrame from the list of data | |
df = pd.DataFrame(data_list) | |
return df | |