TRAIL / app.py
jitinpatronus's picture
Update app.py
2c4cfd0 verified
import gradio as gr
import pandas as pd
import os
import shutil
import json
from zipfile import ZipFile
import re
# Function to load leaderboard data from a CSV file
def load_leaderboard_data(csv_file_path):
try:
df = pd.read_csv(csv_file_path)
return df
except Exception as e:
print(f"Error loading CSV file: {e}")
return pd.DataFrame()
def save_zip_and_extract_json(zip_path):
if not zip_path:
return "Please upload a ZIP file."
try:
# 1) Determine Space name and persistent base dir
cwd = os.getcwd()
space_name = os.path.basename(cwd)
base_dir = os.path.join("data", space_name, "uploaded_jsons")
os.makedirs(base_dir, exist_ok=True)
# 2) Copy the zip into base_dir
zip_dest = os.path.join(base_dir, os.path.basename(zip_path))
shutil.copy(zip_path, zip_dest)
# 3) Extract only .json files
extracted = []
with ZipFile(zip_dest, 'r') as archive:
for member in archive.namelist():
if member.lower().endswith(".json"):
archive.extract(member, path=base_dir)
extracted.append(member)
if not extracted:
return "No JSON files found in the ZIP."
return f"Extracted JSON files:\n" + "\n".join(extracted)
except Exception as e:
return f"Error processing ZIP file: {str(e)}"
# Load the leaderboard data
leaderboard1 = load_leaderboard_data("leaderboard_swe.csv")
leaderboard2 = load_leaderboard_data("leaderboard_gaia.csv")
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# TRAIL: Trace Reasoning and Agentic Issue Localization Leaderboard")
with gr.Tab("πŸ† LEADERBOARD"):
with gr.Row():
with gr.Column():
gr.Markdown("## TRAIL-SWE Leaderboard")
gr.Dataframe(leaderboard1)
with gr.Column():
gr.Markdown("## TRAIL-GAIA Leaderboard")
gr.Dataframe(leaderboard2)
with gr.Tab("πŸš€ SUBMIT"):
gr.Markdown("## Submit Your Results as ZIP")
gr.Markdown("See instructions in README before submitting.")
#with gr.Row():
with gr.Column():
file_input = gr.File(
label="Upload ZIP File",
file_types=['.zip']
)
submit_button = gr.Button("Submit", interactive=True)
output = gr.Textbox(label="Status")
def process_upload(file):
if file is None:
return "Please upload a ZIP file."
try:
return save_zip_and_extract_json(file.name)
except Exception as e:
return f"Error: {str(e)}"
submit_button.click(
fn=process_upload,
inputs=file_input,
outputs=output
)
with open("README.md", "r", encoding="utf-8") as f:
README_CONTENT = f.read()
yaml_front_matter = re.compile(r"^---\s*.*?\s*---\s*", re.DOTALL)
readme_content_without_yaml = re.sub(yaml_front_matter, "", README_CONTENT).strip()
with gr.Tab("πŸ“– README"):
gr.Markdown(readme_content_without_yaml)
if __name__ == "__main__":
demo.launch()