adding live submission, definitely wont work at first go
Browse files
app.py
CHANGED
@@ -7,22 +7,62 @@ from gradio_leaderboard import Leaderboard
|
|
7 |
from evaluation import evaluate_problem
|
8 |
|
9 |
from utils import read_submission_from_hub, write_results
|
10 |
-
from about import ASSAY_LIST, ASSAY_RENAME, ASSAY_EMOJIS
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
raise gr.Error(f'Evaluation failed: {e}. No results written to results dataset.')
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def get_leaderboard_table(assay: str | None = None):
|
28 |
# ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
|
@@ -37,7 +77,8 @@ def get_leaderboard_table(assay: str | None = None):
|
|
37 |
|
38 |
# Previously hosted on HF hub, local for now (Can also pull directly from github backend)
|
39 |
column_order = ["model", "property", "spearman", "spearman_abs"] # "assay",
|
40 |
-
|
|
|
41 |
df["property"] = df["assay"].map(ASSAY_RENAME)
|
42 |
df = df.query("assay.isin(@ASSAY_RENAME.keys())")
|
43 |
if assay is not None:
|
@@ -109,87 +150,50 @@ with gr.Blocks() as demo:
|
|
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 |
-
# # gr.LoginButton()
|
157 |
-
|
158 |
-
# with gr.Row():
|
159 |
-
# with gr.Column():
|
160 |
-
# problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
|
161 |
-
# username_input = gr.Textbox(
|
162 |
-
# label="Username",
|
163 |
-
# placeholder="Enter your Hugging Face username",
|
164 |
-
# info="This will be displayed on the leaderboard."
|
165 |
-
# )
|
166 |
-
# with gr.Column():
|
167 |
-
# boundary_file = gr.File(label="Boundary JSON File (.json)")
|
168 |
-
|
169 |
-
# username_input.change(
|
170 |
-
# fn=lambda x: x if x.strip() else None,
|
171 |
-
# inputs=username_input,
|
172 |
-
# outputs=user_state
|
173 |
-
# )
|
174 |
-
|
175 |
-
# submit_btn = gr.Button("Evaluate")
|
176 |
-
# message = gr.Textbox(label="Status", lines=1, visible=False)
|
177 |
-
# # help message
|
178 |
-
# gr.Markdown("If you have issues with submission or using the leaderboard, please start a discussion in the Community tab of this Space.")
|
179 |
-
|
180 |
-
# submit_btn.click(
|
181 |
-
# submit_boundary,
|
182 |
-
# inputs=[problem_type, boundary_file, user_state],
|
183 |
-
# outputs=[message, filename],
|
184 |
-
# ).then(
|
185 |
-
# fn=show_output_box,
|
186 |
-
# inputs=[message],
|
187 |
-
# outputs=[message],
|
188 |
-
# ).then(
|
189 |
-
# fn=evaluate_boundary,
|
190 |
-
# inputs=[filename],
|
191 |
-
# outputs=[eval_state]
|
192 |
-
# )
|
193 |
|
194 |
|
195 |
if __name__ == "__main__":
|
|
|
7 |
from evaluation import evaluate_problem
|
8 |
|
9 |
from utils import read_submission_from_hub, write_results
|
10 |
+
from about import ASSAY_LIST, ASSAY_RENAME, ASSAY_EMOJIS, submissions_repo, API, results_repo
|
11 |
+
from typing import BinaryIO, Literal
|
12 |
+
from datetime import datetime
|
13 |
+
import tempfile
|
14 |
+
from datasets import load_dataset
|
15 |
+
|
16 |
+
def make_submission(problem_type,
|
17 |
+
submitted_file: BinaryIO,
|
18 |
+
user_state):
|
19 |
+
|
20 |
+
if user_state is None:
|
21 |
+
raise gr.Error("You must submit your username to submit a file.")
|
|
|
22 |
|
23 |
+
file_path = submitted_file.name
|
24 |
+
|
25 |
+
if not file_path:
|
26 |
+
raise gr.Error("Uploaded file object does not have a valid file path.")
|
27 |
+
|
28 |
+
path_obj = Path(file_path)
|
29 |
+
timestamp = datetime.utcnow().isoformat()
|
30 |
+
|
31 |
+
with (
|
32 |
+
path_obj.open("rb") as f_in,
|
33 |
+
tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp_boundary,
|
34 |
+
):
|
35 |
+
file_content = f_in.read()
|
36 |
+
tmp_boundary.write(file_content)
|
37 |
+
tmp_boundary_path = Path(tmp_boundary.name)
|
38 |
+
|
39 |
+
# write to dataset
|
40 |
+
filename = f"{problem_type}/{timestamp.replace(':', '-')}_{problem_type}.json"
|
41 |
+
record = {
|
42 |
+
"submission_filename": filename,
|
43 |
+
"submission_time": timestamp,
|
44 |
+
"problem_type": problem_type,
|
45 |
+
"csv_content": file_content,
|
46 |
+
"evaluated": False,
|
47 |
+
"user": user_state,
|
48 |
+
}
|
49 |
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
|
50 |
+
json.dump(record, tmp, indent=2)
|
51 |
+
tmp.flush()
|
52 |
+
tmp_name = tmp.name
|
53 |
+
|
54 |
+
API.upload_file(
|
55 |
+
path_or_fileobj=tmp_name,
|
56 |
+
path_in_repo=filename,
|
57 |
+
repo_id=submissions_repo,
|
58 |
+
repo_type="dataset",
|
59 |
+
commit_message=f"Add submission for {problem_type} at {timestamp}"
|
60 |
+
)
|
61 |
+
Path(tmp_name).unlink()
|
62 |
+
|
63 |
+
tmp_boundary_path.unlink()
|
64 |
+
|
65 |
+
return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly."
|
66 |
|
67 |
def get_leaderboard_table(assay: str | None = None):
|
68 |
# ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
|
|
|
77 |
|
78 |
# Previously hosted on HF hub, local for now (Can also pull directly from github backend)
|
79 |
column_order = ["model", "property", "spearman", "spearman_abs"] # "assay",
|
80 |
+
ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
|
81 |
+
df = pd.DataFrame(ds).drop_duplicates(subset=["model", "assay"])
|
82 |
df["property"] = df["assay"].map(ASSAY_RENAME)
|
83 |
df = df.query("assay.isin(@ASSAY_RENAME.keys())")
|
84 |
if assay is not None:
|
|
|
150 |
"""
|
151 |
)
|
152 |
|
153 |
+
with gr.TabItem("✉️ Submit", elem_id="boundary-benchmark-tab-table"):
|
154 |
+
gr.Markdown(
|
155 |
+
"""
|
156 |
+
# Antibody Developability Submission
|
157 |
+
Upload a CSV to get a score!
|
158 |
+
"""
|
159 |
+
)
|
160 |
+
filename = gr.State(value=None)
|
161 |
+
eval_state = gr.State(value=None)
|
162 |
+
user_state = gr.State(value=None)
|
163 |
+
|
164 |
+
# gr.LoginButton()
|
165 |
+
|
166 |
+
with gr.Row():
|
167 |
+
with gr.Column():
|
168 |
+
problem_type = gr.Dropdown(ASSAY_LIST, label="Problem Type")
|
169 |
+
username_input = gr.Textbox(
|
170 |
+
label="Username",
|
171 |
+
placeholder="Enter your Hugging Face username",
|
172 |
+
info="This will be displayed on the leaderboard."
|
173 |
+
)
|
174 |
+
with gr.Column():
|
175 |
+
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
176 |
+
|
177 |
+
username_input.change(
|
178 |
+
fn=lambda x: x if x.strip() else None,
|
179 |
+
inputs=username_input,
|
180 |
+
outputs=user_state
|
181 |
+
)
|
182 |
+
|
183 |
+
submit_btn = gr.Button("Evaluate")
|
184 |
+
message = gr.Textbox(label="Status", lines=1, visible=False)
|
185 |
+
# help message
|
186 |
+
gr.Markdown("If you have issues with submission or using the leaderboard, please start a discussion in the Community tab of this Space.")
|
187 |
+
|
188 |
+
submit_btn.click(
|
189 |
+
make_submission,
|
190 |
+
inputs=[problem_type, boundary_file, user_state],
|
191 |
+
outputs=[message, filename],
|
192 |
+
).then(
|
193 |
+
fn=show_output_box,
|
194 |
+
inputs=[message],
|
195 |
+
outputs=[message],
|
196 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
|
199 |
if __name__ == "__main__":
|