CyberFox commited on
Commit
981a1d5
·
1 Parent(s): 9700858

Spinner while the analysis runs; public API unchanged

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py CHANGED
@@ -358,6 +358,32 @@ def build_stats_html(result: dict) -> str:
358
  # ---------------------------------------------------------------------------
359
  # Gradio handlers
360
  # ---------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  def _error_outputs(message: str, count: int):
362
  html = f'<div class="error-state">{_escape(message)}</div>'
363
  return tuple([html] * count)
@@ -664,6 +690,31 @@ footer { display: none !important; }
664
  color: #4b5563;
665
  font-size: 10px;
666
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667
  .empty-state, .error-state {
668
  padding: 18px;
669
  border: 1px solid #e5e7eb;
@@ -774,9 +825,17 @@ with gr.Blocks(
774
  cards_output = gr.HTML()
775
 
776
  text_btn.click(
 
 
 
 
 
 
 
777
  fn=analyze_text_handler,
778
  inputs=[text_input, lang_dropdown, confidence_slider],
779
  outputs=[stats_output, highlighted_output, cards_output],
 
780
  )
781
 
782
  with gr.TabItem("URL", id="url_tab"):
@@ -822,9 +881,17 @@ with gr.Blocks(
822
  )
823
 
824
  url_btn.click(
 
 
 
 
 
 
 
825
  fn=analyze_url_handler,
826
  inputs=[url_input, url_lang, url_confidence],
827
  outputs=[url_stats, url_highlighted, url_cards, url_extracted],
 
828
  )
829
 
830
 
 
358
  # ---------------------------------------------------------------------------
359
  # Gradio handlers
360
  # ---------------------------------------------------------------------------
361
+ def _pending_html(message: str) -> str:
362
+ return (
363
+ '<div class="analysis-pending" role="status" aria-live="polite">'
364
+ '<span class="analysis-spinner" aria-hidden="true"></span>'
365
+ f'<span>{_escape(message)}</span>'
366
+ '</div>'
367
+ )
368
+
369
+
370
+ def _pending_text():
371
+ """Shown the moment Analyze is pressed, before the API answers."""
372
+ return (
373
+ _pending_html("Analyzing text…"),
374
+ _pending_html("Detecting entities…"),
375
+ _pending_html("Resolving identities…"),
376
+ )
377
+
378
+
379
+ def _pending_url():
380
+ return (
381
+ _pending_html("Fetching the page…"),
382
+ _pending_html("Extracting and detecting entities…"),
383
+ _pending_html("Resolving identities…"),
384
+ )
385
+
386
+
387
  def _error_outputs(message: str, count: int):
388
  html = f'<div class="error-state">{_escape(message)}</div>'
389
  return tuple([html] * count)
 
690
  color: #4b5563;
691
  font-size: 10px;
692
  }
693
+ .analysis-pending {
694
+ display: flex;
695
+ align-items: center;
696
+ gap: 10px;
697
+ padding: 16px 18px;
698
+ border: 1px solid #e5e7eb;
699
+ border-radius: 12px;
700
+ background: #fff;
701
+ color: #4b5563;
702
+ font-size: 14px;
703
+ }
704
+ .analysis-spinner {
705
+ width: 16px;
706
+ height: 16px;
707
+ border: 2px solid #dbe2f5;
708
+ border-top-color: #3554d9;
709
+ border-radius: 50%;
710
+ animation: analysis-spin 0.7s linear infinite;
711
+ flex: none;
712
+ }
713
+ @keyframes analysis-spin { to { transform: rotate(360deg); } }
714
+ @media (prefers-reduced-motion: reduce) {
715
+ .analysis-spinner { animation-duration: 2.4s; }
716
+ }
717
+
718
  .empty-state, .error-state {
719
  padding: 18px;
720
  border: 1px solid #e5e7eb;
 
825
  cards_output = gr.HTML()
826
 
827
  text_btn.click(
828
+ fn=_pending_text,
829
+ inputs=None,
830
+ outputs=[stats_output, highlighted_output, cards_output],
831
+ queue=False,
832
+ show_progress="hidden",
833
+ api_name=False,
834
+ ).then(
835
  fn=analyze_text_handler,
836
  inputs=[text_input, lang_dropdown, confidence_slider],
837
  outputs=[stats_output, highlighted_output, cards_output],
838
+ api_name="analyze_text_handler",
839
  )
840
 
841
  with gr.TabItem("URL", id="url_tab"):
 
881
  )
882
 
883
  url_btn.click(
884
+ fn=_pending_url,
885
+ inputs=None,
886
+ outputs=[url_stats, url_highlighted, url_cards],
887
+ queue=False,
888
+ show_progress="hidden",
889
+ api_name=False,
890
+ ).then(
891
  fn=analyze_url_handler,
892
  inputs=[url_input, url_lang, url_confidence],
893
  outputs=[url_stats, url_highlighted, url_cards, url_extracted],
894
+ api_name="analyze_url_handler",
895
  )
896
 
897