cgeorgiaw HF Staff commited on
Commit
240a1de
·
1 Parent(s): 11e5e48

adding live submission, definitely wont work at first go

Browse files
Files changed (1) hide show
  1. app.py +101 -97
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
- def evaluate_boundary(filename):
13
- print(filename)
14
- local_path = read_submission_from_hub(filename)
15
- with Path(local_path).open("r") as f:
16
- raw = f.read()
17
- data_dict = json.loads(raw)
18
-
19
- try:
20
- result = evaluate_problem(data_dict['problem_type'], local_path)
21
- except Exception as e:
22
- raise gr.Error(f'Evaluation failed: {e}. No results written to results dataset.')
23
 
24
- write_results(data_dict, result)
25
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- df = pd.read_csv("data/metrics_all.csv").drop_duplicates(subset=["model", "assay"])
 
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
- # dropdown = gr.Dropdown(choices=filenames, label="Choose a file")
113
- # plot_output = gr.Plot()
114
-
115
- # with gr.TabItem("🔍 Visualize", elem_id="boundary-benchmark-tab-table"):
116
- # ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
117
- # full_df = pd.DataFrame(ds)
118
- # filenames = full_df['result_filename'].to_list()
119
- # with gr.Row():
120
- # with gr.Column():
121
- # dropdown = gr.Dropdown(choices=filenames, label="Choose a leaderboard entry", value=filenames[0])
122
- # rld_btn = gr.Button(value="Reload")
123
-
124
- # with gr.Column():
125
- # plot = gr.Plot()
126
-
127
- # def get_boundary_vis(selected_file):
128
- # local_path = read_result_from_hub(selected_file)
129
- # with Path(local_path).open("r") as f:
130
- # raw = f.read()
131
- # data_dict = json.loads(raw)
132
- # boundary_json = data_dict['boundary_json']
133
-
134
- # if data_dict['problem_type'] == 'mhd_stable':
135
- # raise gr.Error("Sorry this isn't implemented for mhd_stable submissions yet!")
136
- # else:
137
- # boundary = load_boundary(boundary_json)
138
-
139
- # vis = make_visual(boundary)
140
- # return vis
141
-
142
- # demo.load(get_boundary_vis, dropdown, plot)
143
- # rld_btn.click(get_boundary_vis, dropdown, plot)
144
-
145
- # with gr.TabItem("✉️ Submit", elem_id="boundary-benchmark-tab-table"):
146
- # gr.Markdown(
147
- # """
148
- # # Plasma Boundary Evaluation Submission
149
- # Upload your plasma boundary JSON and select the problem type to get your score.
150
- # """
151
- # )
152
- # filename = gr.State(value=None)
153
- # eval_state = gr.State(value=None)
154
- # user_state = gr.State(value=None)
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__":