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