Shiyu Zhao
commited on
Commit
·
d9a1db1
1
Parent(s):
2c8dbc2
Update space
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Sample data based on your table (you'll need to update this with the full dataset)
|
6 |
data_synthesized_full = {
|
@@ -55,6 +59,187 @@ df_synthesized_full = pd.DataFrame(data_synthesized_full)
|
|
55 |
df_synthesized_10 = pd.DataFrame(data_synthesized_10)
|
56 |
df_human_generated = pd.DataFrame(data_human_generated)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def format_dataframe(df, dataset):
|
59 |
# Filter the dataframe for the selected dataset
|
60 |
columns = ['Method'] + [col for col in df.columns if dataset in col]
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
from datetime import datetime
|
6 |
+
import json
|
7 |
+
|
8 |
|
9 |
# Sample data based on your table (you'll need to update this with the full dataset)
|
10 |
data_synthesized_full = {
|
|
|
59 |
df_synthesized_10 = pd.DataFrame(data_synthesized_10)
|
60 |
df_human_generated = pd.DataFrame(data_human_generated)
|
61 |
|
62 |
+
def validate_email(email_str):
|
63 |
+
"""Validate email format(s)"""
|
64 |
+
emails = [e.strip() for e in email_str.split(';')]
|
65 |
+
email_pattern = re.compile(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
|
66 |
+
return all(email_pattern.match(email) for email in emails)
|
67 |
+
|
68 |
+
def validate_github_url(url):
|
69 |
+
"""Validate GitHub URL format"""
|
70 |
+
github_pattern = re.compile(
|
71 |
+
r'^https?:\/\/(?:www\.)?github\.com\/[\w-]+\/[\w.-]+\/?$'
|
72 |
+
)
|
73 |
+
return bool(github_pattern.match(url))
|
74 |
+
|
75 |
+
def validate_csv(file_obj):
|
76 |
+
"""Validate CSV file format and content"""
|
77 |
+
try:
|
78 |
+
df = pd.read_csv(file_obj.name)
|
79 |
+
required_cols = ['query_id', 'pred_rank']
|
80 |
+
|
81 |
+
# Check columns
|
82 |
+
if not all(col in df.columns for col in required_cols):
|
83 |
+
return False, "CSV must contain 'query_id' and 'pred_rank' columns"
|
84 |
+
|
85 |
+
# Check pred_rank format and length
|
86 |
+
try:
|
87 |
+
first_rank = eval(df['pred_rank'].iloc[0]) if isinstance(df['pred_rank'].iloc[0], str) else df['pred_rank'].iloc[0]
|
88 |
+
if not isinstance(first_rank, list) or len(first_rank) < 20:
|
89 |
+
return False, "pred_rank must be a list with at least 20 candidates"
|
90 |
+
except:
|
91 |
+
return False, "Invalid pred_rank format"
|
92 |
+
|
93 |
+
return True, "Valid CSV file"
|
94 |
+
except Exception as e:
|
95 |
+
return False, f"Error processing CSV: {str(e)}"
|
96 |
+
|
97 |
+
def save_submission(submission_data):
|
98 |
+
"""Save submission data to a JSON file"""
|
99 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
100 |
+
submission_id = f"{submission_data['team_name']}_{timestamp}"
|
101 |
+
|
102 |
+
# Create submissions directory if it doesn't exist
|
103 |
+
os.makedirs("submissions", exist_ok=True)
|
104 |
+
|
105 |
+
# Save submission data
|
106 |
+
submission_path = f"submissions/{submission_id}.json"
|
107 |
+
with open(submission_path, 'w') as f:
|
108 |
+
json.dump(submission_data, f, indent=4)
|
109 |
+
|
110 |
+
return submission_id
|
111 |
+
|
112 |
+
def process_submission(
|
113 |
+
method_name, team_name, dataset, split, contact_email,
|
114 |
+
code_repo, csv_file, model_description, hardware, paper_link
|
115 |
+
):
|
116 |
+
"""Process and validate submission"""
|
117 |
+
# Validation checks
|
118 |
+
if len(method_name) > 25:
|
119 |
+
return "Error: Method name must be 25 characters or less"
|
120 |
+
if len(team_name) > 25:
|
121 |
+
return "Error: Team name must be 25 characters or less"
|
122 |
+
if not validate_email(contact_email):
|
123 |
+
return "Error: Invalid email format"
|
124 |
+
if not validate_github_url(code_repo):
|
125 |
+
return "Error: Invalid GitHub repository URL"
|
126 |
+
|
127 |
+
# Validate CSV file
|
128 |
+
csv_valid, csv_message = validate_csv(csv_file)
|
129 |
+
if not csv_valid:
|
130 |
+
return f"Error with CSV file: {csv_message}"
|
131 |
+
|
132 |
+
# Process CSV file through evaluation pipeline
|
133 |
+
try:
|
134 |
+
results = compute_metrics(
|
135 |
+
csv_file.name,
|
136 |
+
dataset=dataset.lower(),
|
137 |
+
split=split,
|
138 |
+
num_workers=4
|
139 |
+
)
|
140 |
+
|
141 |
+
if isinstance(results, str) and results.startswith("Error"):
|
142 |
+
return f"Evaluation error: {results}"
|
143 |
+
|
144 |
+
# Prepare submission data
|
145 |
+
submission_data = {
|
146 |
+
"method_name": method_name,
|
147 |
+
"team_name": team_name,
|
148 |
+
"dataset": dataset,
|
149 |
+
"split": split,
|
150 |
+
"contact_email": contact_email,
|
151 |
+
"code_repo": code_repo,
|
152 |
+
"model_description": model_description,
|
153 |
+
"hardware": hardware,
|
154 |
+
"paper_link": paper_link,
|
155 |
+
"results": results,
|
156 |
+
"status": "pending_review",
|
157 |
+
"submission_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
158 |
+
}
|
159 |
+
|
160 |
+
# Save submission
|
161 |
+
submission_id = save_submission(submission_data)
|
162 |
+
|
163 |
+
return f"""
|
164 |
+
Submission successful! Your submission ID is: {submission_id}
|
165 |
+
|
166 |
+
Evaluation Results:
|
167 |
+
Hit@1: {results['hit@1']:.2f}
|
168 |
+
Hit@5: {results['hit@5']:.2f}
|
169 |
+
Recall@20: {results['recall@20']:.2f}
|
170 |
+
MRR: {results['mrr']:.2f}
|
171 |
+
|
172 |
+
Your submission is pending review. You will receive an email notification once the review is complete.
|
173 |
+
"""
|
174 |
+
|
175 |
+
except Exception as e:
|
176 |
+
return f"Error processing submission: {str(e)}"
|
177 |
+
|
178 |
+
# Add this to your existing Gradio interface
|
179 |
+
def add_submission_form(demo):
|
180 |
+
with demo:
|
181 |
+
gr.Markdown("## Submit Your Results")
|
182 |
+
gr.Markdown("""
|
183 |
+
Submit your results to be included in the leaderboard. Please ensure your submission meets all requirements.
|
184 |
+
For questions, contact stark-qa@cs.stanford.edu
|
185 |
+
""")
|
186 |
+
|
187 |
+
with gr.Form(elem_id="submission_form"):
|
188 |
+
method_name = gr.Textbox(
|
189 |
+
label="Method Name (max 25 chars)",
|
190 |
+
placeholder="e.g., MyRetrievalModel-v1"
|
191 |
+
)
|
192 |
+
team_name = gr.Textbox(
|
193 |
+
label="Team Name (max 25 chars)",
|
194 |
+
placeholder="e.g., Stanford NLP"
|
195 |
+
)
|
196 |
+
dataset = gr.Dropdown(
|
197 |
+
choices=["amazon", "mag", "prime"],
|
198 |
+
label="Dataset"
|
199 |
+
)
|
200 |
+
split = gr.Dropdown(
|
201 |
+
choices=["test", "test-0.1", "human_generated_eval"],
|
202 |
+
label="Split",
|
203 |
+
value="test"
|
204 |
+
)
|
205 |
+
contact_email = gr.Textbox(
|
206 |
+
label="Contact Email(s)",
|
207 |
+
placeholder="email@example.com; another@example.com"
|
208 |
+
)
|
209 |
+
code_repo = gr.Textbox(
|
210 |
+
label="Code Repository",
|
211 |
+
placeholder="https://github.com/username/repository"
|
212 |
+
)
|
213 |
+
csv_file = gr.File(
|
214 |
+
label="Prediction CSV",
|
215 |
+
file_types=[".csv"]
|
216 |
+
)
|
217 |
+
model_description = gr.Textbox(
|
218 |
+
label="Model Description",
|
219 |
+
lines=3,
|
220 |
+
placeholder="Briefly describe how your retriever model works..."
|
221 |
+
)
|
222 |
+
hardware = gr.Textbox(
|
223 |
+
label="Hardware Specifications",
|
224 |
+
placeholder="e.g., 4x NVIDIA A100 80GB"
|
225 |
+
)
|
226 |
+
paper_link = gr.Textbox(
|
227 |
+
label="Paper Link (Optional)",
|
228 |
+
placeholder="https://arxiv.org/abs/..."
|
229 |
+
)
|
230 |
+
|
231 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
232 |
+
result = gr.Textbox(label="Submission Status", interactive=False)
|
233 |
+
|
234 |
+
submit_btn.click(
|
235 |
+
process_submission,
|
236 |
+
inputs=[
|
237 |
+
method_name, team_name, dataset, split, contact_email,
|
238 |
+
code_repo, csv_file, model_description, hardware, paper_link
|
239 |
+
],
|
240 |
+
outputs=result
|
241 |
+
)
|
242 |
+
|
243 |
def format_dataframe(df, dataset):
|
244 |
# Filter the dataframe for the selected dataset
|
245 |
columns = ['Method'] + [col for col in df.columns if dataset in col]
|