Spaces:
Sleeping
Sleeping
Jitin Krishnan
commited on
Commit
·
dc70710
1
Parent(s):
c7a004d
Update space
Browse files- README.md +19 -2
- app.py +22 -10
- database.py +119 -70
- model +6 -0
- models.json +6 -0
README.md
CHANGED
|
@@ -11,7 +11,6 @@ license: mit
|
|
| 11 |
short_description: 'TRAIL: Trace Reasoning and Agentic Issue Localization'
|
| 12 |
sdk_version: 5.19.0
|
| 13 |
---
|
| 14 |
-
|
| 15 |
# Model Performance Leaderboard
|
| 16 |
|
| 17 |
This is a Hugging Face Space that hosts a leaderboard for comparing model performances across various metrics.
|
|
@@ -23,6 +22,24 @@ This is a Hugging Face Space that hosts a leaderboard for comparing model perfor
|
|
| 23 |
- **Integrated Backend**: Stores all submissions with timestamp and attribution
|
| 24 |
- **Customizable Metrics**: Configure which metrics to display and track
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
## How to Use
|
| 27 |
|
| 28 |
### Viewing the Leaderboard
|
|
@@ -66,4 +83,4 @@ This leaderboard is built using:
|
|
| 66 |
|
| 67 |
## License
|
| 68 |
|
| 69 |
-
This project is open source and available under the MIT license.
|
|
|
|
| 11 |
short_description: 'TRAIL: Trace Reasoning and Agentic Issue Localization'
|
| 12 |
sdk_version: 5.19.0
|
| 13 |
---
|
|
|
|
| 14 |
# Model Performance Leaderboard
|
| 15 |
|
| 16 |
This is a Hugging Face Space that hosts a leaderboard for comparing model performances across various metrics.
|
|
|
|
| 22 |
- **Integrated Backend**: Stores all submissions with timestamp and attribution
|
| 23 |
- **Customizable Metrics**: Configure which metrics to display and track
|
| 24 |
|
| 25 |
+
## Installation
|
| 26 |
+
|
| 27 |
+
### Setting Up Your Space
|
| 28 |
+
|
| 29 |
+
1. Upload all files to your Hugging Face Space
|
| 30 |
+
2. Make sure to make `start.sh` executable:
|
| 31 |
+
```bash
|
| 32 |
+
chmod +x start.sh
|
| 33 |
+
```
|
| 34 |
+
3. Configure your Space to use the `start.sh` script as the entry point
|
| 35 |
+
|
| 36 |
+
### Troubleshooting Installation Issues
|
| 37 |
+
|
| 38 |
+
If you encounter JSON parsing errors:
|
| 39 |
+
1. Check if `models.json` exists and is a valid JSON file
|
| 40 |
+
2. Run `python setup.py` to regenerate configuration files
|
| 41 |
+
3. If problems persist, delete the `models.json` file and let the setup script create a new one
|
| 42 |
+
|
| 43 |
## How to Use
|
| 44 |
|
| 45 |
### Viewing the Leaderboard
|
|
|
|
| 83 |
|
| 84 |
## License
|
| 85 |
|
| 86 |
+
This project is open source and available under the MIT license.
|
app.py
CHANGED
|
@@ -3,17 +3,29 @@ import json
|
|
| 3 |
import pandas as pd
|
| 4 |
import datetime
|
| 5 |
import os
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def format_leaderboard_data(submissions):
|
| 19 |
"""Format submissions data for the leaderboard display"""
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import datetime
|
| 5 |
import os
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
|
| 9 |
+
# Add better error handling for initial setup
|
| 10 |
+
try:
|
| 11 |
+
from database import Database, load_config
|
| 12 |
+
|
| 13 |
+
# Initialize database
|
| 14 |
+
db = Database()
|
| 15 |
+
config = load_config()
|
| 16 |
+
|
| 17 |
+
# Set up the title and description from config
|
| 18 |
+
title = config.get("title", "Model Leaderboard")
|
| 19 |
+
description = config.get("description", "Submit and compare model performances")
|
| 20 |
+
metrics = config.get("metrics", ["accuracy"])
|
| 21 |
+
main_metric = config.get("main_metric", metrics[0] if metrics else "accuracy")
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"Error during initialization: {e}")
|
| 24 |
+
# Set fallback values in case of error
|
| 25 |
+
title = "Model Leaderboard"
|
| 26 |
+
description = "Submit and compare model performances"
|
| 27 |
+
metrics = ["accuracy"]
|
| 28 |
+
main_metric = "accuracy"
|
| 29 |
|
| 30 |
def format_leaderboard_data(submissions):
|
| 31 |
"""Format submissions data for the leaderboard display"""
|
database.py
CHANGED
|
@@ -1,80 +1,129 @@
|
|
| 1 |
-
import
|
| 2 |
import json
|
|
|
|
| 3 |
import datetime
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
# Add
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
file_path = os.path.join(self.submission_dir, f"{submission_id}.json")
|
| 24 |
-
with open(file_path, 'w') as f:
|
| 25 |
-
json.dump(submission, f, indent=2)
|
| 26 |
-
|
| 27 |
-
return submission_id
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
return None
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
with open(file_path, 'r') as f:
|
| 44 |
-
submissions.append(json.load(f))
|
| 45 |
-
return submissions
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
"""Delete a submission by ID"""
|
| 59 |
-
file_path = os.path.join(self.submission_dir, f"{submission_id}.json")
|
| 60 |
-
if os.path.exists(file_path):
|
| 61 |
-
os.remove(file_path)
|
| 62 |
-
return True
|
| 63 |
-
return False
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
import datetime
|
| 5 |
+
import os
|
| 6 |
+
from database import Database, load_config
|
| 7 |
|
| 8 |
+
# Initialize database
|
| 9 |
+
db = Database()
|
| 10 |
+
config = load_config()
|
| 11 |
+
|
| 12 |
+
# Set up the title and description from config
|
| 13 |
+
title = config.get("title", "Model Leaderboard")
|
| 14 |
+
description = config.get("description", "Submit and compare model performances")
|
| 15 |
+
metrics = config.get("metrics", ["accuracy"])
|
| 16 |
+
main_metric = config.get("main_metric", metrics[0])
|
| 17 |
+
|
| 18 |
+
def format_leaderboard_data(submissions):
|
| 19 |
+
"""Format submissions data for the leaderboard display"""
|
| 20 |
+
if not submissions:
|
| 21 |
+
return pd.DataFrame()
|
| 22 |
+
|
| 23 |
+
# Extract relevant fields for display
|
| 24 |
+
data = []
|
| 25 |
+
for sub in submissions:
|
| 26 |
+
entry = {
|
| 27 |
+
"Model": sub["model_name"],
|
| 28 |
+
"Submitted by": sub["submitter_name"],
|
| 29 |
+
"Date": sub["timestamp"].split("T")[0],
|
| 30 |
+
}
|
| 31 |
|
| 32 |
+
# Add all metrics from the submission
|
| 33 |
+
for metric in metrics:
|
| 34 |
+
if metric in sub:
|
| 35 |
+
entry[metric.replace("_", " ").title()] = f"{sub[metric]:.4f}"
|
| 36 |
|
| 37 |
+
data.append(entry)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
return pd.DataFrame(data)
|
| 40 |
+
|
| 41 |
+
def add_submission(model_name, submitter_name, description, **metric_values):
|
| 42 |
+
"""Add a new submission to the leaderboard"""
|
| 43 |
+
if not model_name or not submitter_name:
|
| 44 |
+
return "Model name and submitter name are required.", None
|
|
|
|
| 45 |
|
| 46 |
+
# Create submission dictionary
|
| 47 |
+
submission = {
|
| 48 |
+
"model_name": model_name,
|
| 49 |
+
"submitter_name": submitter_name,
|
| 50 |
+
"description": description,
|
| 51 |
+
}
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# Add metrics
|
| 54 |
+
for metric in metrics:
|
| 55 |
+
metric_key = f"{metric}_input"
|
| 56 |
+
if metric_key in metric_values and metric_values[metric_key]:
|
| 57 |
+
try:
|
| 58 |
+
submission[metric] = float(metric_values[metric_key])
|
| 59 |
+
except ValueError:
|
| 60 |
+
return f"Invalid value for {metric}. Please enter a number.", None
|
| 61 |
+
|
| 62 |
+
# Add submission to database
|
| 63 |
+
submission_id = db.add_submission(submission)
|
| 64 |
+
|
| 65 |
+
# Update leaderboard
|
| 66 |
+
submissions = db.get_leaderboard(sort_by=main_metric, ascending=False)
|
| 67 |
+
leaderboard_df = format_leaderboard_data(submissions)
|
| 68 |
|
| 69 |
+
return f"Submission added successfully! ID: {submission_id}", leaderboard_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
def update_leaderboard(sort_metric=main_metric, ascending=False):
|
| 72 |
+
"""Get the current leaderboard data"""
|
| 73 |
+
submissions = db.get_leaderboard(sort_by=sort_metric, ascending=ascending)
|
| 74 |
+
return format_leaderboard_data(submissions)
|
| 75 |
+
|
| 76 |
+
# Create the Gradio interface
|
| 77 |
+
with gr.Blocks() as app:
|
| 78 |
+
gr.Markdown(f"# {title}")
|
| 79 |
+
gr.Markdown(description)
|
| 80 |
+
|
| 81 |
+
with gr.Tabs():
|
| 82 |
+
with gr.TabItem("Leaderboard"):
|
| 83 |
+
sort_metric = gr.Dropdown(
|
| 84 |
+
choices=[m.replace("_", " ").title() for m in metrics],
|
| 85 |
+
value=main_metric.replace("_", " ").title(),
|
| 86 |
+
label="Sort by"
|
| 87 |
+
)
|
| 88 |
+
sort_order = gr.Checkbox(label="Ascending order")
|
| 89 |
+
leaderboard = gr.DataFrame(update_leaderboard())
|
| 90 |
+
refresh_btn = gr.Button("Refresh Leaderboard")
|
| 91 |
+
|
| 92 |
+
def handle_sort(metric, ascending):
|
| 93 |
+
metric_key = metric.lower().replace(" ", "_")
|
| 94 |
+
return update_leaderboard(sort_metric=metric_key, ascending=ascending)
|
| 95 |
+
|
| 96 |
+
sort_metric.change(handle_sort, [sort_metric, sort_order], leaderboard)
|
| 97 |
+
sort_order.change(handle_sort, [sort_metric, sort_order], leaderboard)
|
| 98 |
+
refresh_btn.click(handle_sort, [sort_metric, sort_order], leaderboard)
|
| 99 |
+
|
| 100 |
+
with gr.TabItem("Submit Model"):
|
| 101 |
+
with gr.Column():
|
| 102 |
+
model_name = gr.Textbox(label="Model Name")
|
| 103 |
+
submitter = gr.Textbox(label="Your Name")
|
| 104 |
+
model_desc = gr.Textbox(label="Model Description (optional)", lines=3)
|
| 105 |
+
|
| 106 |
+
# Create metric input fields
|
| 107 |
+
metric_inputs = {}
|
| 108 |
+
with gr.Column():
|
| 109 |
+
for metric in metrics:
|
| 110 |
+
metric_inputs[f"{metric}_input"] = gr.Number(
|
| 111 |
+
label=f"{metric.replace('_', ' ').title()}",
|
| 112 |
+
min=0,
|
| 113 |
+
max=1 if "accuracy" in metric or "score" in metric else None
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
submit_btn = gr.Button("Submit Model")
|
| 117 |
+
result = gr.Textbox(label="Result")
|
| 118 |
+
|
| 119 |
+
# Connect submission function
|
| 120 |
+
inputs = [model_name, submitter, model_desc] + list(metric_inputs.values())
|
| 121 |
+
submit_btn.click(
|
| 122 |
+
add_submission,
|
| 123 |
+
inputs=[model_name, submitter, model_desc] + list(metric_inputs.values()),
|
| 124 |
+
outputs=[result, leaderboard],
|
| 125 |
+
kwargs=metric_inputs
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
app.launch(debug=True)
|
model
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "Model Performance Leaderboard",
|
| 3 |
+
"description": "This leaderboard tracks and compares model performance across multiple metrics. Submit your model results to see how they stack up!",
|
| 4 |
+
"metrics": ["accuracy", "f1_score", "precision", "recall"],
|
| 5 |
+
"main_metric": "accuracy"
|
| 6 |
+
}
|
models.json
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "Model Performance Leaderboard",
|
| 3 |
+
"description": "This leaderboard tracks and compares model performance across multiple metrics. Submit your model results to see how they stack up!",
|
| 4 |
+
"metrics": ["accuracy", "f1_score", "precision", "recall"],
|
| 5 |
+
"main_metric": "accuracy"
|
| 6 |
+
}
|