Sdm0 commited on
Commit
027f744
Β·
verified Β·
1 Parent(s): 1a55bdc

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. app.py +80 -9
app.py CHANGED
@@ -277,6 +277,21 @@ h1 { display: flex; align-items: center; gap: 10px; }
277
  .footer { text-align: center; color: #9ca3af; font-size: 0.85em; padding: 20px 0; }
278
  details { margin-top: 8px; }
279
  details summary { cursor: pointer; color: #4b5563; font-weight: 500; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  """
281
 
282
  with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
@@ -305,8 +320,16 @@ with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
305
  precision=0,
306
  scale=1,
307
  )
308
- run_btn = gr.Button("β–Ά Run Review", variant="primary", size="lg")
309
 
 
 
 
 
 
 
 
 
 
310
  status_msg = gr.Markdown(visible=False)
311
 
312
  with gr.Column(visible=False) as results_panel:
@@ -323,21 +346,37 @@ with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
323
  # ── Event wiring ──────────────────────────────────────────────
324
  def on_run_click(*args):
325
  """Generator that clears old state, runs review, shows results."""
 
 
 
 
 
 
 
 
 
 
326
  for result, err in run_review(*args):
327
  if err:
328
  yield [
329
- *[None, None, None, None],
 
 
330
  gr.update(visible=True, value=err),
 
331
  gr.update(visible=False),
332
  ]
333
  else:
334
  verdict_html, findings_html, count_html, config_json = result
335
  yield [
 
 
 
 
336
  gr.update(value=verdict_html),
337
  gr.update(value=count_html),
338
  gr.update(value=findings_html),
339
  config_json,
340
- gr.update(visible=False),
341
  gr.update(visible=True),
342
  ]
343
 
@@ -345,14 +384,18 @@ with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
345
  fn=on_run_click,
346
  inputs=[repo_input, pr_input],
347
  outputs=[
 
 
 
 
348
  verdict_display,
349
  count_display,
350
  findings_display,
351
  pr_state,
352
- status_msg,
353
  results_panel,
354
  ],
355
  )
 
356
 
357
  def on_approve(config_json):
358
  msg = resume_review(config_json, "approve")
@@ -379,7 +422,15 @@ with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
379
  "Run the review pipeline on **synthetic demo data** "
380
  "(no API keys needed, no interrupt required)."
381
  )
382
- smoke_btn = gr.Button("β–Ά Run Smoke Test", variant="primary", size="lg")
 
 
 
 
 
 
 
 
383
 
384
  with gr.Column(visible=False) as smoke_results:
385
  smoke_verdict = gr.HTML()
@@ -389,31 +440,51 @@ with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
389
  smoke_reject = gr.Button("❌ Reject (demo)", variant="secondary")
390
  smoke_resume_msg = gr.Markdown()
391
 
 
 
392
  def on_smoke_click():
 
 
 
 
 
 
 
 
 
 
 
393
  for result, err in run_smoke():
394
  if err:
395
  yield [
396
- gr.update(visible=True, value=err),
 
 
397
  gr.update(visible=False),
398
  None,
399
  gr.update(value=""),
400
  gr.update(value=""),
 
401
  ]
402
  else:
403
  verdict_html, findings_html, config_json, s_verdict, s_findings = result
404
  yield [
 
405
  gr.update(visible=False),
406
  gr.update(visible=True),
 
407
  config_json,
408
  gr.update(value=s_verdict),
409
  gr.update(value=s_findings),
 
410
  ]
411
 
412
- smoke_btn.click(
413
  fn=on_smoke_click,
414
- outputs=[status_msg, smoke_results, smoke_state,
415
- smoke_verdict, smoke_findings],
416
  )
 
417
 
418
  smoke_approve.click(
419
  fn=lambda c: resume_review(c, "approve"),
 
277
  .footer { text-align: center; color: #9ca3af; font-size: 0.85em; padding: 20px 0; }
278
  details { margin-top: 8px; }
279
  details summary { cursor: pointer; color: #4b5563; font-weight: 500; }
280
+
281
+ /* Loading spinner */
282
+ @keyframes spin { to { transform: rotate(360deg); } }
283
+ .loading-spinner {
284
+ display: flex; align-items: center; gap: 12px;
285
+ padding: 24px 0; justify-content: center;
286
+ }
287
+ .loading-spinner .spinner {
288
+ width: 24px; height: 24px; border: 3px solid #e5e7eb;
289
+ border-top-color: #6366f1; border-radius: 50%;
290
+ animation: spin 0.8s linear infinite;
291
+ }
292
+ .loading-spinner .label {
293
+ color: #6b7280; font-size: 0.95em;
294
+ }
295
  """
296
 
297
  with gr.Blocks(css=CSS, title="OpenCodeReview", theme=gr.themes.Soft()) as demo:
 
320
  precision=0,
321
  scale=1,
322
  )
 
323
 
324
+ with gr.Row():
325
+ run_btn = gr.Button("β–Ά Run Review", variant="primary", size="lg", scale=2)
326
+ cancel_btn = gr.Button("⏹ Cancel", variant="stop", size="lg", visible=False)
327
+
328
+ loading_box = gr.HTML(
329
+ '<div class="loading-spinner"><div class="spinner"></div>'
330
+ '<span class="label">Running review pipeline...</span></div>',
331
+ visible=False,
332
+ )
333
  status_msg = gr.Markdown(visible=False)
334
 
335
  with gr.Column(visible=False) as results_panel:
 
346
  # ── Event wiring ──────────────────────────────────────────────
347
  def on_run_click(*args):
348
  """Generator that clears old state, runs review, shows results."""
349
+ # Yield initial loading state
350
+ yield [
351
+ gr.update(visible=True),
352
+ gr.update(visible=True, variant="stop"),
353
+ gr.update(visible=False),
354
+ gr.update(visible=False, value=""),
355
+ *[None, None, None, None],
356
+ gr.update(visible=False),
357
+ ]
358
+
359
  for result, err in run_review(*args):
360
  if err:
361
  yield [
362
+ gr.update(visible=False),
363
+ gr.update(visible=False),
364
+ gr.update(visible=True),
365
  gr.update(visible=True, value=err),
366
+ *[None, None, None, None],
367
  gr.update(visible=False),
368
  ]
369
  else:
370
  verdict_html, findings_html, count_html, config_json = result
371
  yield [
372
+ gr.update(visible=False),
373
+ gr.update(visible=False),
374
+ gr.update(visible=True),
375
+ gr.update(visible=False),
376
  gr.update(value=verdict_html),
377
  gr.update(value=count_html),
378
  gr.update(value=findings_html),
379
  config_json,
 
380
  gr.update(visible=True),
381
  ]
382
 
 
384
  fn=on_run_click,
385
  inputs=[repo_input, pr_input],
386
  outputs=[
387
+ loading_box,
388
+ cancel_btn,
389
+ run_btn,
390
+ status_msg,
391
  verdict_display,
392
  count_display,
393
  findings_display,
394
  pr_state,
 
395
  results_panel,
396
  ],
397
  )
398
+ cancel_btn.click(fn=None, cancels=[run_event])
399
 
400
  def on_approve(config_json):
401
  msg = resume_review(config_json, "approve")
 
422
  "Run the review pipeline on **synthetic demo data** "
423
  "(no API keys needed, no interrupt required)."
424
  )
425
+ with gr.Row():
426
+ smoke_btn = gr.Button("β–Ά Run Smoke Test", variant="primary", size="lg", scale=2)
427
+ smoke_cancel_btn = gr.Button("⏹ Cancel", variant="stop", size="lg", visible=False)
428
+
429
+ smoke_loading = gr.HTML(
430
+ '<div class="loading-spinner"><div class="spinner"></div>'
431
+ '<span class="label">Running smoke test...</span></div>',
432
+ visible=False,
433
+ )
434
 
435
  with gr.Column(visible=False) as smoke_results:
436
  smoke_verdict = gr.HTML()
 
440
  smoke_reject = gr.Button("❌ Reject (demo)", variant="secondary")
441
  smoke_resume_msg = gr.Markdown()
442
 
443
+ smoke_status = gr.Markdown(visible=False)
444
+
445
  def on_smoke_click():
446
+ # Show loading state
447
+ yield [
448
+ gr.update(visible=True),
449
+ gr.update(visible=True, variant="stop"),
450
+ gr.update(visible=False),
451
+ gr.update(visible=False),
452
+ None,
453
+ gr.update(value=""),
454
+ gr.update(value=""),
455
+ gr.update(visible=False),
456
+ ]
457
  for result, err in run_smoke():
458
  if err:
459
  yield [
460
+ gr.update(visible=False),
461
+ gr.update(visible=False),
462
+ gr.update(visible=True),
463
  gr.update(visible=False),
464
  None,
465
  gr.update(value=""),
466
  gr.update(value=""),
467
+ gr.update(visible=True, value=err),
468
  ]
469
  else:
470
  verdict_html, findings_html, config_json, s_verdict, s_findings = result
471
  yield [
472
+ gr.update(visible=False),
473
  gr.update(visible=False),
474
  gr.update(visible=True),
475
+ gr.update(visible=True),
476
  config_json,
477
  gr.update(value=s_verdict),
478
  gr.update(value=s_findings),
479
+ gr.update(visible=False),
480
  ]
481
 
482
+ smoke_event = smoke_btn.click(
483
  fn=on_smoke_click,
484
+ outputs=[smoke_loading, smoke_cancel_btn, smoke_btn, smoke_results, smoke_state,
485
+ smoke_verdict, smoke_findings, smoke_status],
486
  )
487
+ smoke_cancel_btn.click(fn=None, cancels=[smoke_event])
488
 
489
  smoke_approve.click(
490
  fn=lambda c: resume_review(c, "approve"),