Jitin Krishnan commited on
Commit
dc70710
·
1 Parent(s): c7a004d

Update space

Browse files
Files changed (5) hide show
  1. README.md +19 -2
  2. app.py +22 -10
  3. database.py +119 -70
  4. model +6 -0
  5. 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
- 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"""
 
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 os
2
  import json
 
3
  import datetime
4
- from pathlib import Path
5
- import numpy as np
6
 
7
- class Database:
8
- def __init__(self, submission_dir="submissions"):
9
- self.submission_dir = submission_dir
10
- os.makedirs(submission_dir, exist_ok=True)
11
-
12
- def add_submission(self, submission):
13
- """Add a new submission to the database"""
14
- # Generate a timestamp and ID for the submission
15
- timestamp = datetime.datetime.now().isoformat()
16
- submission_id = f"{submission['model_name'].replace(' ', '_')}_{timestamp.replace(':', '-')}"
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Add timestamp and ID to submission
19
- submission['timestamp'] = timestamp
20
- submission['id'] = submission_id
 
21
 
22
- # Save submission to a JSON file
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
- def get_submission(self, submission_id):
30
- """Get a specific submission by ID"""
31
- file_path = os.path.join(self.submission_dir, f"{submission_id}.json")
32
- if os.path.exists(file_path):
33
- with open(file_path, 'r') as f:
34
- return json.load(f)
35
- return None
36
 
37
- def get_all_submissions(self):
38
- """Get all submissions"""
39
- submissions = []
40
- for file_name in os.listdir(self.submission_dir):
41
- if file_name.endswith('.json'):
42
- file_path = os.path.join(self.submission_dir, file_name)
43
- with open(file_path, 'r') as f:
44
- submissions.append(json.load(f))
45
- return submissions
46
 
47
- def get_leaderboard(self, sort_by="score", ascending=False):
48
- """Get submissions sorted for leaderboard display"""
49
- submissions = self.get_all_submissions()
50
-
51
- # Sort submissions
52
- if sort_by in submissions[0] if submissions else False:
53
- submissions.sort(key=lambda x: x.get(sort_by, 0), reverse=not ascending)
54
-
55
- return submissions
 
 
 
 
 
 
56
 
57
- def delete_submission(self, submission_id):
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
- # Load leaderboard configuration
66
- def load_config():
67
- if os.path.exists("models.json"):
68
- with open("models.json", "r") as f:
69
- return json.load(f)
70
- else:
71
- # Default configuration
72
- config = {
73
- "title": "Model Leaderboard",
74
- "description": "Submit and compare model performances",
75
- "metrics": ["accuracy", "f1_score", "precision", "recall"],
76
- "main_metric": "accuracy"
77
- }
78
- with open("models.json", "w") as f:
79
- json.dump(config, f, indent=2)
80
- return config
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }