Spaces:
Running
Running
added more submission logic
Browse files
app.py
CHANGED
|
@@ -131,9 +131,74 @@ def update_leaderboard(show_percentage, selected_groups, compact_view, cached_df
|
|
| 131 |
def show_output_box(message):
|
| 132 |
return gr.update(value=message, visible=True)
|
| 133 |
|
| 134 |
-
def submit_cif_files(problem_type, cif_files, relaxed, profile: gr.OAuthProfile | None):
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
def generate_metric_legend_html():
|
| 139 |
"""Generate HTML table with color-coded metric group legend."""
|
|
@@ -287,15 +352,19 @@ def gradio_interface() -> gr.Blocks:
|
|
| 287 |
|
| 288 |
with gr.Row():
|
| 289 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
|
| 291 |
with gr.Column():
|
| 292 |
cif_file = gr.File(label="Upload a CSV, a pkl, or a ZIP of CIF files.")
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
)
|
| 299 |
|
| 300 |
submit_btn = gr.Button("Submission")
|
| 301 |
message = gr.Textbox(label="Status", lines=1, visible=False)
|
|
@@ -304,7 +373,7 @@ def gradio_interface() -> gr.Blocks:
|
|
| 304 |
|
| 305 |
submit_btn.click(
|
| 306 |
submit_cif_files,
|
| 307 |
-
inputs=[problem_type, cif_file, relaxed],
|
| 308 |
outputs=[message, filename],
|
| 309 |
).then(
|
| 310 |
fn=show_output_box,
|
|
|
|
| 131 |
def show_output_box(message):
|
| 132 |
return gr.update(value=message, visible=True)
|
| 133 |
|
| 134 |
+
def submit_cif_files(model_name, problem_type, cif_files, relaxed, profile: gr.OAuthProfile | None):
|
| 135 |
+
"""Submit structures to the leaderboard."""
|
| 136 |
+
from huggingface_hub import upload_file
|
| 137 |
+
|
| 138 |
+
# Validate inputs
|
| 139 |
+
if not model_name or not model_name.strip():
|
| 140 |
+
return "Error: Please provide a model name.", None
|
| 141 |
+
|
| 142 |
+
if not problem_type:
|
| 143 |
+
return "Error: Please select a problem type.", None
|
| 144 |
+
|
| 145 |
+
if not cif_files:
|
| 146 |
+
return "Error: Please upload a file.", None
|
| 147 |
+
|
| 148 |
+
if not profile:
|
| 149 |
+
return "Error: Please log in to submit.", None
|
| 150 |
+
|
| 151 |
+
try:
|
| 152 |
+
username = profile.username
|
| 153 |
+
timestamp = datetime.now().isoformat()
|
| 154 |
+
|
| 155 |
+
# Create submission metadata
|
| 156 |
+
submission_data = {
|
| 157 |
+
"username": username,
|
| 158 |
+
"model_name": model_name.strip(),
|
| 159 |
+
"problem_type": problem_type,
|
| 160 |
+
"relaxed": relaxed,
|
| 161 |
+
"timestamp": timestamp,
|
| 162 |
+
"file_name": Path(cif_files).name
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
# Create a unique submission ID
|
| 166 |
+
submission_id = f"{username}_{model_name.strip().replace(' ', '_')}_{timestamp.replace(':', '-')}"
|
| 167 |
+
|
| 168 |
+
# Upload the submission file
|
| 169 |
+
file_path = Path(cif_files)
|
| 170 |
+
uploaded_file_path = f"submissions/{submission_id}/{file_path.name}"
|
| 171 |
+
|
| 172 |
+
upload_file(
|
| 173 |
+
path_or_fileobj=str(file_path),
|
| 174 |
+
path_in_repo=uploaded_file_path,
|
| 175 |
+
repo_id=submissions_repo,
|
| 176 |
+
token=TOKEN,
|
| 177 |
+
repo_type="dataset"
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
# Upload metadata as JSON
|
| 181 |
+
metadata_path = f"submissions/{submission_id}/metadata.json"
|
| 182 |
+
import tempfile
|
| 183 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
| 184 |
+
json.dump(submission_data, f, indent=2)
|
| 185 |
+
temp_metadata_path = f.name
|
| 186 |
+
|
| 187 |
+
upload_file(
|
| 188 |
+
path_or_fileobj=temp_metadata_path,
|
| 189 |
+
path_in_repo=metadata_path,
|
| 190 |
+
repo_id=submissions_repo,
|
| 191 |
+
token=TOKEN,
|
| 192 |
+
repo_type="dataset"
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# Clean up temp file
|
| 196 |
+
os.unlink(temp_metadata_path)
|
| 197 |
+
|
| 198 |
+
return f"Success! Submitted {model_name} for {problem_type} evaluation. Submission ID: {submission_id}", submission_id
|
| 199 |
+
|
| 200 |
+
except Exception as e:
|
| 201 |
+
return f"Error during submission: {str(e)}", None
|
| 202 |
|
| 203 |
def generate_metric_legend_html():
|
| 204 |
"""Generate HTML table with color-coded metric group legend."""
|
|
|
|
| 352 |
|
| 353 |
with gr.Row():
|
| 354 |
with gr.Column():
|
| 355 |
+
model_name_input = gr.Textbox(
|
| 356 |
+
label="Model Name",
|
| 357 |
+
placeholder="Enter your model name",
|
| 358 |
+
info="Provide a name for your model/method"
|
| 359 |
+
)
|
| 360 |
problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
|
| 361 |
with gr.Column():
|
| 362 |
cif_file = gr.File(label="Upload a CSV, a pkl, or a ZIP of CIF files.")
|
| 363 |
+
relaxed = gr.Checkbox(
|
| 364 |
+
value=False,
|
| 365 |
+
label="Structures are already relaxed",
|
| 366 |
+
info="Check this box if your submitted structures have already been relaxed"
|
| 367 |
+
)
|
|
|
|
| 368 |
|
| 369 |
submit_btn = gr.Button("Submission")
|
| 370 |
message = gr.Textbox(label="Status", lines=1, visible=False)
|
|
|
|
| 373 |
|
| 374 |
submit_btn.click(
|
| 375 |
submit_cif_files,
|
| 376 |
+
inputs=[model_name_input, problem_type, cif_file, relaxed],
|
| 377 |
outputs=[message, filename],
|
| 378 |
).then(
|
| 379 |
fn=show_output_box,
|