Spaces:
Sleeping
Sleeping
File size: 10,658 Bytes
998c769 4b720fd e6b05eb 34a6d03 86c5e41 65c47d7 4f58902 65c47d7 4f58902 65a3285 4f58902 4776c27 65a3285 4776c27 65a3285 4776c27 5dccf3f 4776c27 65a3285 4776c27 65a3285 4776c27 65a3285 5dccf3f 65a3285 4776c27 65a3285 b99464a e6b05eb 4f58902 65c47d7 cf91a8f 65a3285 3ed1f96 cb82186 b99464a 3ed1f96 34a6d03 65a3285 3ed1f96 65a3285 cb138e0 4776c27 cb138e0 65a3285 65c47d7 3ed1f96 86c5e41 702e656 fb83d75 702e656 65c47d7 4f58902 65c47d7 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8bddc0b f1e7ab4 8bddc0b f1e7ab4 8532750 f1e7ab4 8bddc0b f1e7ab4 8bddc0b f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8bddc0b f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8bddc0b f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 998c769 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 f1e7ab4 8532750 65c47d7 4776c27 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
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 ZIP"):
gr.Markdown("## Submit Your ZIP of JSONs")
#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()
"""
import gradio as gr
import pandas as pd
import os
import json
import uuid
import hashlib
from datetime import datetime
from huggingface_hub import HfApi, login, HfFolder
# Configuration
LEADERBOARD_CSV = "leaderboard.csv"
SUBMISSIONS_FOLDER = "submissions"
CONFIG_FILE = "config.json"
DEFAULT_COLUMNS = ["rank", "submission_name", "score", "user", "timestamp"]
VERIFY_USERS = False # Set to True to enable HF authentication
# Default configuration
DEFAULT_CONFIG = {
"title": "Hugging Face Competition Leaderboard",
"description": "Submit your results for the competition",
"metric_name": "Score",
"higher_is_better": True,
"max_submissions_per_user": 5,
"allow_submission_edits": True
}
# Ensure submissions folder exists
os.makedirs(SUBMISSIONS_FOLDER, exist_ok=True)
# Load or create config
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, "r") as f:
config = json.load(f)
else:
config = DEFAULT_CONFIG
with open(CONFIG_FILE, "w") as f:
json.dump(config, f, indent=2)
# Initialize leaderboard if it doesn't exist
if not os.path.exists(LEADERBOARD_CSV):
pd.DataFrame(columns=DEFAULT_COLUMNS).to_csv(LEADERBOARD_CSV, index=False)
def read_leaderboard():
#Read the current leaderboard
if os.path.exists(LEADERBOARD_CSV):
df = pd.read_csv(LEADERBOARD_CSV)
return df
return pd.DataFrame(columns=DEFAULT_COLUMNS)
def verify_user(username, token):
#Verify a user with their Hugging Face token
if not VERIFY_USERS:
return True
try:
api = HfApi(token=token)
user_info = api.whoami()
return user_info["name"] == username
except:
return False
def count_user_submissions(username):
#Count how many submissions a user already has
df = read_leaderboard()
return len(df[df["user"] == username])
def update_leaderboard():
#Update the leaderboard based on submissions
# Read all submissions
submissions = []
for filename in os.listdir(SUBMISSIONS_FOLDER):
if filename.endswith(".json"):
with open(os.path.join(SUBMISSIONS_FOLDER, filename), "r") as f:
try:
data = json.load(f)
submissions.append(data)
except json.JSONDecodeError:
print(f"Error decoding {filename}")
if not submissions:
return pd.DataFrame(columns=DEFAULT_COLUMNS)
# Create dataframe and sort by score
df = pd.DataFrame(submissions)
# Sort based on configuration (higher or lower is better)
ascending = not config.get("higher_is_better", True)
df = df.sort_values("score", ascending=ascending)
# Add rank
df["rank"] = range(1, len(df) + 1)
# Save updated leaderboard
df.to_csv(LEADERBOARD_CSV, index=False)
return df
def submit(submission_name, score, username, hf_token="", submission_details=None):
#Add a new submission to the leaderboard
if not submission_name or not username:
return "Submission name and username are required", None
try:
score = float(score)
except ValueError:
return "Score must be a valid number", None
# Verify user if enabled
if VERIFY_USERS and not verify_user(username, hf_token):
return "Invalid Hugging Face credentials", None
# Check submission limit
max_submissions = config.get("max_submissions_per_user", 5)
if count_user_submissions(username) >= max_submissions:
return f"You've reached the maximum of {max_submissions} submissions", None
# Create submission entry
submission_id = str(uuid.uuid4())[:8]
submission = {
"submission_id": submission_id,
"submission_name": submission_name,
"score": score,
"user": username,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
# Add optional details
if submission_details:
submission["details"] = submission_details
# Save submission to file
filename = f"{username}_{submission_name.replace(' ', '_')}_{submission_id}.json"
with open(os.path.join(SUBMISSIONS_FOLDER, filename), "w") as f:
json.dump(submission, f)
# Update leaderboard
leaderboard = update_leaderboard()
return f"Submission '{submission_name}' added successfully!", leaderboard
def render_leaderboard():
#Display the current leaderboard
df = update_leaderboard()
if len(df) == 0:
return "No submissions yet."
# Format the dataframe for display
display_df = df[DEFAULT_COLUMNS].copy()
return display_df
# Create the Gradio interface
with gr.Blocks(title=config["title"]) as demo:
gr.Markdown(f"# {config['title']}")
gr.Markdown(f"{config['description']}")
with gr.Tab("Leaderboard"):
gr.Markdown("## Current Rankings")
metric_name = config.get("metric_name", "Score")
higher_better = "higher is better" if config.get("higher_is_better", True) else "lower is better"
gr.Markdown(f"*Ranked by {metric_name} ({higher_better})*")
leaderboard_output = gr.Dataframe(
headers=["Rank", "Submission", metric_name, "User", "Timestamp"],
datatype=["number", "str", "number", "str", "str"],
interactive=False
)
refresh_btn = gr.Button("Refresh Leaderboard")
refresh_btn.click(render_leaderboard, inputs=[], outputs=[leaderboard_output])
with gr.Tab("Submit"):
gr.Markdown("## Submit Your Results")
with gr.Row():
with gr.Column():
submission_name = gr.Textbox(label="Submission Name", placeholder="MyAwesomeModel v1.0")
score = gr.Number(label=metric_name, precision=4)
username = gr.Textbox(label="Username", placeholder="Your Hugging Face username")
# Only show token field if verification is enabled
if VERIFY_USERS:
hf_token = gr.Textbox(
label="Hugging Face Token",
placeholder="hf_...",
type="password"
)
else:
hf_token = gr.Textbox(visible=False)
submission_details = gr.Textbox(
label="Additional Details (optional)",
placeholder="Model details, training info, etc.",
lines=5
)
submit_btn = gr.Button("Submit to Leaderboard")
submit_output = gr.Markdown()
submission_leaderboard = gr.Dataframe(
headers=["Rank", "Submission", metric_name, "User", "Timestamp"],
datatype=["number", "str", "number", "str", "str"],
interactive=False
)
submit_btn.click(
submit,
inputs=[submission_name, score, username, hf_token, submission_details],
outputs=[submit_output, submission_leaderboard]
)
# Add admin tab if desired
with gr.Tab("About"):
gr.Markdown("## About This Leaderboard")
# Initialize the leaderboard on load
demo.load(render_leaderboard, inputs=[], outputs=[leaderboard_output])
if __name__ == "__main__":
demo.launch()
"""
|