michaelr27 HF Staff commited on
Commit
7655daf
·
verified ·
1 Parent(s): ef37489

submit: drop invisible button-progress bar

Browse files
Files changed (1) hide show
  1. submit.py +13 -26
submit.py CHANGED
@@ -166,7 +166,6 @@ class _HubWriteError(Exception):
166
  def handle_submit(
167
  zip_file,
168
  profile: gr.OAuthProfile | None,
169
- progress: gr.Progress = gr.Progress(),
170
  ) -> None:
171
  """Validate a submission upload; surface progress + outcome via toasts.
172
 
@@ -177,18 +176,19 @@ def handle_submit(
177
  defensively if it's called without a profile so a UI mishap
178
  can't write an anonymous row.
179
 
180
- Side-effect-only (returns ``None``): in-flight status drives the
181
- Gradio submit button's progress tracker (``progress(fraction,
182
- desc=...)``), and the final outcome lands in a ``gr.Info`` /
183
- ``gr.Error`` toast. Rejection paths raise ``gr.Error``, which
184
- Gradio surfaces as a red toast and aborts the handler; the outer
185
- ``try/finally`` still runs to clean up the temp dir.
186
 
187
- Progress milestones on the happy path: extract zip (0.05),
188
- validate meta (0.15), check fixture set (0.30), parse STEPs
189
- (0.45), dedup hash + Hub check (0.70), upload zip (0.85), queue
190
- eval (0.95), queued (1.0). The single ``gr.Info("Submission <id>
191
- queued ...")`` toast fires after the worker is spawned.
 
192
 
193
  On rejection (login-missing, form-level, validation gate, dedup,
194
  or Hub write), a single ``gr.Error`` toast carries the message;
@@ -202,9 +202,7 @@ def handle_submit(
202
 
203
  # Immediate ack on click. The eval itself (after queuing) is the
204
  # slow part, so hint at the wall time up front so the user knows
205
- # what to expect instead of waiting on a silent button. Restored
206
- # after commit ed2a486 dropped the bookend toast in favour of a
207
- # button-progress tracker.
208
  gr.Info(
209
  "Validating submission... evaluation usually takes "
210
  "~1 minute after queuing."
@@ -221,17 +219,10 @@ def handle_submit(
221
  run_dir = tmp / "run"
222
  run_dir.mkdir()
223
  try:
224
- progress(0.05, desc="Extracting zip")
225
  try:
226
  _extract_zip(zip_path, run_dir)
227
- progress(0.15, desc="Validating meta.json")
228
  meta = _load_and_validate_meta(run_dir)
229
- progress(0.30, desc="Checking fixture set")
230
  fixture_names = _validate_fixture_set(run_dir)
231
- progress(
232
- 0.45,
233
- desc=f"Parsing {len(fixture_names)} STEP files",
234
- )
235
  _validate_steps_parseable(run_dir, fixture_names)
236
  except _ValidationError as e:
237
  raise gr.Error(f"Submission rejected: {e}")
@@ -239,7 +230,6 @@ def handle_submit(
239
  # Dedup gate: hash the raw zip bytes and reject if an existing
240
  # row carries the same hash. Runs after validation so a clearly
241
  # malformed upload still gets the specific validation error.
242
- progress(0.70, desc="Checking for duplicates")
243
  zip_sha256 = _compute_sha256(zip_path)
244
  existing_id = _find_existing_submission_by_sha256(zip_sha256)
245
  if existing_id is not None:
@@ -253,19 +243,16 @@ def handle_submit(
253
  meta["submitter_name"], meta["submission_name"]
254
  )
255
  try:
256
- progress(0.85, desc="Uploading submission")
257
  blob_url = _upload_submission_zip(submission_id, zip_path)
258
  row = _build_pending_row(
259
  submission_id, meta, blob_url, zip_sha256,
260
  hf_username=profile.username,
261
  )
262
- progress(0.95, desc="Queuing evaluation")
263
  _append_pending_row(row)
264
  except _HubWriteError as e:
265
  raise gr.Error(f"Submission rejected: {e}")
266
 
267
  _spawn_worker(submission_id, blob_url)
268
- progress(1.0, desc="Queued")
269
  gr.Info(
270
  f"Submission {submission_id} queued for evaluation "
271
  f"({len(fixture_names)} fixtures). The eval runs on an "
 
166
  def handle_submit(
167
  zip_file,
168
  profile: gr.OAuthProfile | None,
 
169
  ) -> None:
170
  """Validate a submission upload; surface progress + outcome via toasts.
171
 
 
176
  defensively if it's called without a profile so a UI mishap
177
  can't write an anonymous row.
178
 
179
+ Side-effect-only (returns ``None``): in-flight status surfaces via
180
+ ``gr.Info`` toasts (validating on click, queued after the worker
181
+ spawns) and ``gr.Error`` toasts for rejections. Rejection paths
182
+ raise ``gr.Error``, which Gradio surfaces as a red toast and
183
+ aborts the handler; the outer ``try/finally`` still runs to clean
184
+ up the temp dir.
185
 
186
+ Toasts on the happy path:
187
+
188
+ 1. ``"Validating submission..."`` on click, with a wall-time hint
189
+ so the user knows the post-queue eval takes ~1 minute.
190
+ 2. ``"Submission <id> queued ..."`` once the row + zip are on the
191
+ Hub and the worker has been spawned.
192
 
193
  On rejection (login-missing, form-level, validation gate, dedup,
194
  or Hub write), a single ``gr.Error`` toast carries the message;
 
202
 
203
  # Immediate ack on click. The eval itself (after queuing) is the
204
  # slow part, so hint at the wall time up front so the user knows
205
+ # what to expect instead of waiting on a silent button.
 
 
206
  gr.Info(
207
  "Validating submission... evaluation usually takes "
208
  "~1 minute after queuing."
 
219
  run_dir = tmp / "run"
220
  run_dir.mkdir()
221
  try:
 
222
  try:
223
  _extract_zip(zip_path, run_dir)
 
224
  meta = _load_and_validate_meta(run_dir)
 
225
  fixture_names = _validate_fixture_set(run_dir)
 
 
 
 
226
  _validate_steps_parseable(run_dir, fixture_names)
227
  except _ValidationError as e:
228
  raise gr.Error(f"Submission rejected: {e}")
 
230
  # Dedup gate: hash the raw zip bytes and reject if an existing
231
  # row carries the same hash. Runs after validation so a clearly
232
  # malformed upload still gets the specific validation error.
 
233
  zip_sha256 = _compute_sha256(zip_path)
234
  existing_id = _find_existing_submission_by_sha256(zip_sha256)
235
  if existing_id is not None:
 
243
  meta["submitter_name"], meta["submission_name"]
244
  )
245
  try:
 
246
  blob_url = _upload_submission_zip(submission_id, zip_path)
247
  row = _build_pending_row(
248
  submission_id, meta, blob_url, zip_sha256,
249
  hf_username=profile.username,
250
  )
 
251
  _append_pending_row(row)
252
  except _HubWriteError as e:
253
  raise gr.Error(f"Submission rejected: {e}")
254
 
255
  _spawn_worker(submission_id, blob_url)
 
256
  gr.Info(
257
  f"Submission {submission_id} queued for evaluation "
258
  f"({len(fixture_names)} fixtures). The eval runs on an "