Commit
Β·
823637b
1
Parent(s):
3852c4d
deb
Browse files
app.py
CHANGED
@@ -5,5 +5,5 @@ print(f"[{time.time()}] app.py: Script execution has STARTED.")
|
|
5 |
import os
|
6 |
import subprocess
|
7 |
import src.ui
|
8 |
-
print(f"[{time.time()}] app.py: Imported all.")
|
9 |
# DO NOT add any other imports or code yet.
|
|
|
5 |
import os
|
6 |
import subprocess
|
7 |
import src.ui
|
8 |
+
print(f"[{time.time()}] app.py: Imported all.", flush=True)
|
9 |
# DO NOT add any other imports or code yet.
|
src/ui.py
CHANGED
@@ -2,166 +2,165 @@ import json
|
|
2 |
|
3 |
import gradio as gr
|
4 |
from pathlib import Path
|
5 |
-
print("importedddd1 1", flush=True)
|
6 |
from src.config import SUPPORTED_FRAMEWORKS
|
7 |
|
8 |
from src.hf_utils import load_leaderboard_data, upload_submission, check_name_exists
|
9 |
from src.eval import start_background_evaluation
|
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 |
-
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
from pathlib import Path
|
|
|
5 |
from src.config import SUPPORTED_FRAMEWORKS
|
6 |
|
7 |
from src.hf_utils import load_leaderboard_data, upload_submission, check_name_exists
|
8 |
from src.eval import start_background_evaluation
|
9 |
+
|
10 |
+
|
11 |
+
def handle_upload(submission_name, uploaded_file, report_file, model_framework, progress=gr.Progress()):
|
12 |
+
"""Handle file upload and start evaluation."""
|
13 |
+
if model_framework not in SUPPORTED_FRAMEWORKS:
|
14 |
+
return f"Unsupported modelling framework: {model_framework}. Supported frameworks are: {', '.join(SUPPORTED_FRAMEWORKS)}"
|
15 |
+
|
16 |
+
if not uploaded_file:
|
17 |
+
return "No file uploaded. Please upload a valid submission file."
|
18 |
+
|
19 |
+
if report_file and not report_file.name.endswith(".pdf"):
|
20 |
+
return "Invalid report format. Please upload a PDF file."
|
21 |
+
|
22 |
+
# normalize the submission name
|
23 |
+
submission_name = submission_name.strip().replace(" ", "_").lower()
|
24 |
+
# keep only alphanumeric characters and underscores, restrict to 30 characters
|
25 |
+
submission_name = "".join(
|
26 |
+
c for c in submission_name if c.isalnum() or c == "_"
|
27 |
+
)[:30]
|
28 |
+
|
29 |
+
if not submission_name or submission_name.strip() == "":
|
30 |
+
return "Submission name is required"
|
31 |
+
|
32 |
+
if check_name_exists(submission_name):
|
33 |
+
return f"Submission name '{submission_name}' already exists. Please choose a different name."
|
34 |
+
|
35 |
+
try:
|
36 |
+
progress(0.3, "Uploading to Hugging Face...")
|
37 |
+
|
38 |
+
# Check if the file is a valid JSONL file
|
39 |
+
if not uploaded_file.name.endswith(".jsonl"):
|
40 |
+
return "Invalid file format. Please upload a .jsonl file."
|
41 |
+
|
42 |
+
# Check that the keys in the JSONL file are correct ('id' and 'model')
|
43 |
+
with open(uploaded_file.name, "r") as file:
|
44 |
+
found_one = False
|
45 |
+
for line in file:
|
46 |
+
found_one = True
|
47 |
+
json_object = json.loads(line)
|
48 |
+
if not all(key in json_object for key in ["id", "model"]):
|
49 |
+
return "Invalid content. Each line must contain 'id' and 'model' keys."
|
50 |
+
if not found_one:
|
51 |
+
return "Empty file. Please upload a valid JSONL file."
|
52 |
+
|
53 |
+
success, result = upload_submission(uploaded_file, submission_name, report_file, model_framework)
|
54 |
+
if not success:
|
55 |
+
return f"Upload failed: {result}"
|
56 |
+
|
57 |
+
progress(0.7, "Starting evaluation...")
|
58 |
+
|
59 |
+
# Start evaluation
|
60 |
+
start_background_evaluation(result)
|
61 |
+
|
62 |
+
progress(1.0, "Process complete")
|
63 |
+
return (
|
64 |
+
f"β
Submission '{submission_name}' uploaded successfully!\n"
|
65 |
+
f"Do not worry if the leaderboard does not update immediately; "
|
66 |
+
f"it may take some time for the results to appear (around 5-10 minutes). "
|
67 |
+
f"Feel free to close the tab and check back later.")
|
68 |
+
|
69 |
+
except Exception as e:
|
70 |
+
return f"Error processing upload: {str(e)}"
|
71 |
+
|
72 |
+
|
73 |
+
def create_ui():
|
74 |
+
"""Create and return Gradio UI."""
|
75 |
+
with gr.Blocks(title="Welcome to the CP-Bench leaderboard!") as demo:
|
76 |
+
gr.Markdown("# CP-Bench Leaderboard")
|
77 |
+
gr.Markdown(
|
78 |
+
"This leaderboard is designed to evaluate LLM-generated constraint models for the problems "
|
79 |
+
"in the [CP-Bench](https://huggingface.co/datasets/kostis-init/CP-Bench) dataset."
|
80 |
+
"\n\n"
|
81 |
+
"## How to Submit\n"
|
82 |
+
"1. **Name your submission**: Choose a unique name for your submission (e.g., `my_cool_submission`). "
|
83 |
+
"This name will be used to identify your submission on the leaderboard.\n"
|
84 |
+
"2. **Upload a PDF report**: This is optional, but we highly encourage you to upload a report "
|
85 |
+
" (in PDF format) describing your approach. As this is an open competition, we want to avoid submissions "
|
86 |
+
" that just copy the models from the dataset. The report can be a short description of your approach, "
|
87 |
+
" the models you generated, and any other relevant information.\n"
|
88 |
+
"3. **Upload your submission**: Upload a **single** `.jsonl` file containing the generated models. "
|
89 |
+
" **Each line in the file should be a JSON object with two keys: `id` and `model`.**\n"
|
90 |
+
" * `id`: The ID of the problem exactly as it appears in the original dataset (e.g., `csplib__csplib_001_car_sequencing`).\n"
|
91 |
+
" * `model`: The generated model for the problem (as a string representing runnable code). Make sure that it eventually outputs the solution as a json with key(s) as described in the `decision_variables` entry and values as would be expected in the problem. This is part of the evaluation as well: unexpected keys, or value types are considered incorrect. This is because our automatic evaluation is based on the solution printed by the submitted models.\n"
|
92 |
+
" * An example submission file can be found [here](https://huggingface.co/spaces/kostis-init/CP-Bench-competition/blob/main/sample_submission.jsonl).\n"
|
93 |
+
"3. **Check the leaderboard**: After uploading, you can check the leaderboard to see your results. "
|
94 |
+
"It may take a few minutes for a submission to be evaluated and appear on the leaderboard.\n"
|
95 |
+
"\n\n"
|
96 |
+
"## Important Notes\n"
|
97 |
+
"1. **Submission Name**: The submission name must be different from any existing submission names.\n"
|
98 |
+
"2. **File Format**: Ensure that the uploaded files are in the correct format. The submission file must be a `.jsonl` file, and the report must be a `pdf` file.\n"
|
99 |
+
"3. **Evaluation Script**: It is highly recommended to use the evaluation script provided [here](https://huggingface.co/spaces/kostis-init/CP-Bench-competition/blob/main/user_eval.py) to check your results before submission. You can run the script as follows:\n"
|
100 |
+
" ```bash\n"
|
101 |
+
" python user_eval.py --submission_file path/to/my/submission.jsonl\n"
|
102 |
+
" ```\n"
|
103 |
+
" This will evaluate your submission locally and print the results to the console.\n"
|
104 |
+
"4. **Modelling Frameworks**: Currently, the supported modelling frameworks are MiniZinc, CPMpy and OR-Tools. More frameworks will be added.\n"
|
105 |
+
"\n\n"
|
106 |
+
"### If you have any questions or issues, please feel free to reach out to us TODO\n"
|
107 |
+
"---\n"
|
108 |
+
)
|
109 |
+
|
110 |
+
with gr.Row():
|
111 |
+
with gr.Column(scale=1):
|
112 |
+
gr.Markdown("## π€ Upload Submission")
|
113 |
+
|
114 |
+
submission_name = gr.Textbox(
|
115 |
+
label="Submission Name (required)",
|
116 |
+
placeholder="Enter a unique name for your submission",
|
117 |
+
interactive=True,
|
118 |
+
info="This name will appear on the leaderboard"
|
119 |
+
)
|
120 |
+
model_framework = gr.Dropdown(
|
121 |
+
label="Modelling Framework (required)",
|
122 |
+
choices=SUPPORTED_FRAMEWORKS,
|
123 |
+
value=None,
|
124 |
+
multiselect=False,
|
125 |
+
interactive=True,
|
126 |
+
info="Select the modelling framework used for your submission.",
|
127 |
+
allow_custom_value=False,
|
128 |
+
filterable=False,
|
129 |
+
)
|
130 |
+
|
131 |
+
with gr.Row():
|
132 |
+
report_file = gr.File(
|
133 |
+
label="Upload PDF Report (optional, but recommended)",
|
134 |
+
file_types=[".pdf"],
|
135 |
+
file_count="single",
|
136 |
+
interactive=True,
|
137 |
+
)
|
138 |
+
submission_file = gr.File(
|
139 |
+
label="Upload Submission File (required, .jsonl)",
|
140 |
+
file_types=[".jsonl"],
|
141 |
+
file_count="single",
|
142 |
+
interactive=True,
|
143 |
+
)
|
144 |
+
upload_button = gr.Button("Click to Upload Submission")
|
145 |
+
status_box = gr.Textbox(label="Status", interactive=False)
|
146 |
+
|
147 |
+
with gr.Column(scale=2):
|
148 |
+
gr.Markdown("## π Results Leaderboard")
|
149 |
+
leaderboard = gr.DataFrame(value=load_leaderboard_data, interactive=False)
|
150 |
+
refresh_button = gr.Button("π Refresh Leaderboard")
|
151 |
+
|
152 |
+
# Event handlers
|
153 |
+
upload_button.click(
|
154 |
+
fn=handle_upload,
|
155 |
+
inputs=[submission_name, submission_file, report_file, model_framework],
|
156 |
+
outputs=[status_box],
|
157 |
+
show_progress="full",
|
158 |
+
)
|
159 |
+
|
160 |
+
refresh_button.click(
|
161 |
+
fn=load_leaderboard_data,
|
162 |
+
inputs=None,
|
163 |
+
outputs=[leaderboard]
|
164 |
+
)
|
165 |
+
|
166 |
+
return demo
|