cgeorgiaw HF Staff commited on
Commit
92d0002
·
1 Parent(s): 88e80bb

changing to username input

Browse files
Files changed (2) hide show
  1. app.py +18 -4
  2. submit.py +7 -4
app.py CHANGED
@@ -141,18 +141,32 @@ def gradio_interface() -> gr.Blocks:
141
  )
142
  filename = gr.State(value=None)
143
  eval_state = gr.State(value=None)
 
144
 
145
- gr.LoginButton()
146
 
147
  with gr.Row():
148
- problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
149
- boundary_file = gr.File(label="Boundary JSON File (.json)")
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  submit_btn = gr.Button("Evaluate")
152
  message = gr.Textbox(label="Status", lines=1, visible=False)
153
  submit_btn.click(
154
  submit_boundary,
155
- inputs=[problem_type, boundary_file],
156
  outputs=[message, filename],
157
  ).then(
158
  fn=show_output_box,
 
141
  )
142
  filename = gr.State(value=None)
143
  eval_state = gr.State(value=None)
144
+ user_state = gr.State(value=None)
145
 
146
+ # gr.LoginButton()
147
 
148
  with gr.Row():
149
+ with gr.Column():
150
+ problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
151
+ username_input = gr.Textbox(
152
+ label="Username",
153
+ placeholder="Enter your Hugging Face username",
154
+ info="This will be displayed on the leaderboard."
155
+ )
156
+ with gr.Column():
157
+ boundary_file = gr.File(label="Boundary JSON File (.json)")
158
+
159
+ username_input.change(
160
+ fn=lambda x: x if x.strip() else None,
161
+ inputs=username_input,
162
+ outputs=user_state
163
+ )
164
 
165
  submit_btn = gr.Button("Evaluate")
166
  message = gr.Textbox(label="Status", lines=1, visible=False)
167
  submit_btn.click(
168
  submit_boundary,
169
+ inputs=[problem_type, boundary_file, user_state],
170
  outputs=[message, filename],
171
  ).then(
172
  fn=show_output_box,
submit.py CHANGED
@@ -19,12 +19,15 @@ from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, resul
19
  def submit_boundary(
20
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
21
  boundary_file: BinaryIO,
22
- profile: gr.OAuthProfile | None
23
  ) -> str:
24
 
 
 
25
  # error handling
26
- if profile.username is None:
27
- raise gr.Error("You must be logged in to submit a file.")
 
28
 
29
  file_path = boundary_file.name
30
 
@@ -50,7 +53,7 @@ def submit_boundary(
50
  "problem_type": problem_type,
51
  "boundary_json": file_content.decode("utf-8"),
52
  "evaluated": False,
53
- "user": profile.username,
54
  }
55
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
56
  json.dump(record, tmp, indent=2)
 
19
  def submit_boundary(
20
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
21
  boundary_file: BinaryIO,
22
+ user_state
23
  ) -> str:
24
 
25
+ # profile: gr.OAuthProfile | None
26
+
27
  # error handling
28
+ # if profile.username is None:
29
+ if user_state is None:
30
+ raise gr.Error("You must submit your username to submit a file.")
31
 
32
  file_path = boundary_file.name
33
 
 
53
  "problem_type": problem_type,
54
  "boundary_json": file_content.decode("utf-8"),
55
  "evaluated": False,
56
+ "user": user_state,
57
  }
58
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
59
  json.dump(record, tmp, indent=2)