cgeorgiaw HF Staff commited on
Commit
e8b7916
·
1 Parent(s): 1e4ed96

still trying to make the leaderboard

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -23,11 +23,17 @@ results_repo = "cgeorgiaw/constellaration-results"
23
  def submit_boundary(
24
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
25
  boundary_file: BinaryIO,
 
26
  ) -> str:
27
 
 
 
 
 
28
  file_path = boundary_file.name
 
29
  if not file_path:
30
- return "Error: Uploaded file object does not have a valid file path."
31
 
32
  path_obj = pathlib.Path(file_path)
33
  timestamp = datetime.utcnow().isoformat()
@@ -48,6 +54,7 @@ def submit_boundary(
48
  "problem_type": problem_type,
49
  "boundary_json": file_content.decode("utf-8"),
50
  "evaluated": False,
 
51
  }
52
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
53
  json.dump(record, tmp, indent=2)
@@ -106,7 +113,7 @@ def write_results(record, result):
106
  pathlib.Path(tmp_name).unlink()
107
  return
108
 
109
- def get_user_profile(profile: gr.OAuthProfile | None) -> str:
110
  if profile is None:
111
  return "Please login to submit a boundary for evaluation."
112
  return profile.name
@@ -148,9 +155,11 @@ def gradio_interface() -> gr.Blocks:
148
  """
149
  )
150
 
 
 
151
  gr.LoginButton()
152
- m1 = gr.Markdown()
153
- demo.load(get_user_profile, inputs=None, outputs=m1)
154
 
155
  with gr.Row():
156
  problem_type = gr.Dropdown(
@@ -163,7 +172,7 @@ def gradio_interface() -> gr.Blocks:
163
  submit_btn = gr.Button("Evaluate")
164
  submit_btn.click(
165
  submit_boundary,
166
- inputs=[problem_type, boundary_file],
167
  outputs=output,
168
  )
169
 
 
23
  def submit_boundary(
24
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
25
  boundary_file: BinaryIO,
26
+ user_state,
27
  ) -> str:
28
 
29
+ # error handling
30
+ if user_state is None:
31
+ raise gr.Error("You must be logged in to submit a file.")
32
+
33
  file_path = boundary_file.name
34
+
35
  if not file_path:
36
+ raise gr.Error("Uploaded file object does not have a valid file path.")
37
 
38
  path_obj = pathlib.Path(file_path)
39
  timestamp = datetime.utcnow().isoformat()
 
54
  "problem_type": problem_type,
55
  "boundary_json": file_content.decode("utf-8"),
56
  "evaluated": False,
57
+ "user": user_state,
58
  }
59
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
60
  json.dump(record, tmp, indent=2)
 
113
  pathlib.Path(tmp_name).unlink()
114
  return
115
 
116
+ def get_user(profile: gr.OAuthProfile | None) -> str:
117
  if profile is None:
118
  return "Please login to submit a boundary for evaluation."
119
  return profile.name
 
155
  """
156
  )
157
 
158
+ user_state = gr.State(value=None)
159
+
160
  gr.LoginButton()
161
+
162
+ demo.load(get_user, inputs=None, outputs=user_state)
163
 
164
  with gr.Row():
165
  problem_type = gr.Dropdown(
 
172
  submit_btn = gr.Button("Evaluate")
173
  submit_btn.click(
174
  submit_boundary,
175
+ inputs=[problem_type, boundary_file, user_state],
176
  outputs=output,
177
  )
178