jrrribeiro commited on
Commit
5d694ae
·
1 Parent(s): 58e27c7

fix: solid status color and coalesced refresh to eliminate flicker

Browse files
Files changed (1) hide show
  1. src/ui/upload_app_factory.py +47 -7
src/ui/upload_app_factory.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import tarfile
2
  import tempfile
3
  import threading
@@ -15,6 +16,37 @@ from cli.hf_dataset_cli import ensure_project_dataset_structure, ingest_segments
15
  _HF_TOKEN_LOCK = threading.Lock()
16
  _LAST_VALID_HF_TOKEN = ""
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  def _remember_hf_token(token: str) -> None:
20
  clean_token = (token or "").strip()
@@ -91,7 +123,8 @@ def _format_segments_upload_progress(snapshot: dict[str, Any]) -> str:
91
  if processed_pending == 0 and state in {"completed", "failed", "cancelled"}:
92
  processed_pending = min(pending_total, uploaded + failed)
93
 
94
- percent = min(100.0, (processed_pending / pending_total) * 100.0)
 
95
  filled = int(percent // 5)
96
  bar = "█" * filled + "░" * (20 - filled)
97
  return (
@@ -680,6 +713,7 @@ def _setup_dataset_repo(
680
 
681
  def build_upload_app() -> gr.Blocks:
682
  with gr.Blocks(title="BirdNET Dataset Uploader") as demo:
 
683
  gr.Markdown("# BirdNET Dataset Uploader")
684
  gr.Markdown(
685
  "Start in Dataset Repo (HF) to initialize your project repository with the recommended structure. "
@@ -733,9 +767,12 @@ def build_upload_app() -> gr.Blocks:
733
  segments_upload_resume = gr.Button("Resume", variant="secondary")
734
  segments_upload_cancel = gr.Button("Cancel", variant="stop")
735
  segments_upload_refresh = gr.Button("Refresh Status", variant="secondary")
736
- segments_upload_status = gr.Markdown(value="ℹ️ Ready")
737
- segments_upload_progress = gr.Markdown(value="**Progress:** waiting to start")
738
- segments_auto_refresh = gr.Timer(value=0.1, active=False)
 
 
 
739
  segments_last_status_state = gr.State(value="")
740
  segments_last_progress_state = gr.State(value="")
741
 
@@ -763,9 +800,12 @@ def build_upload_app() -> gr.Blocks:
763
  ingestion_resume = gr.Button("Resume", variant="secondary")
764
  ingestion_cancel = gr.Button("Cancel", variant="stop")
765
  ingestion_refresh = gr.Button("Refresh Status", variant="secondary")
766
- ingestion_status = gr.Markdown(value="ℹ️ Ready")
767
- ingestion_progress = gr.Markdown(value="**Progress:** waiting to start")
768
- ingestion_auto_refresh = gr.Timer(value=0.1, active=False)
 
 
 
769
  ingestion_last_status_state = gr.State(value="")
770
  ingestion_last_progress_state = gr.State(value="")
771
 
 
1
+ import os
2
  import tarfile
3
  import tempfile
4
  import threading
 
16
  _HF_TOKEN_LOCK = threading.Lock()
17
  _LAST_VALID_HF_TOKEN = ""
18
 
19
+ _STATUS_REFRESH_SECONDS = max(0.1, float(os.getenv("BIRDNET_STATUS_REFRESH_SECONDS", "0.25")))
20
+ _PROGRESS_PERCENT_STEP = max(0.1, float(os.getenv("BIRDNET_PROGRESS_PERCENT_STEP", "1.0")))
21
+ _SOLID_STATUS_CSS = """
22
+ #segments-upload-status, #segments-upload-status *,
23
+ #segments-upload-progress, #segments-upload-progress *,
24
+ #ingestion-status, #ingestion-status *,
25
+ #ingestion-progress, #ingestion-progress * {
26
+ color: var(--body-text-color) !important;
27
+ opacity: 1 !important;
28
+ }
29
+
30
+ #segments-upload-status p, #segments-upload-progress p,
31
+ #ingestion-status p, #ingestion-progress p {
32
+ margin: 0 !important;
33
+ }
34
+
35
+ #segments-upload-progress strong,
36
+ #ingestion-progress strong {
37
+ color: var(--body-text-color) !important;
38
+ font-weight: 700;
39
+ }
40
+ """
41
+
42
+
43
+ def _quantize_percent(raw_percent: float) -> float:
44
+ step = _PROGRESS_PERCENT_STEP
45
+ if step <= 0:
46
+ return raw_percent
47
+ quantized = round(raw_percent / step) * step
48
+ return max(0.0, min(100.0, quantized))
49
+
50
 
51
  def _remember_hf_token(token: str) -> None:
52
  clean_token = (token or "").strip()
 
123
  if processed_pending == 0 and state in {"completed", "failed", "cancelled"}:
124
  processed_pending = min(pending_total, uploaded + failed)
125
 
126
+ raw_percent = min(100.0, (processed_pending / pending_total) * 100.0)
127
+ percent = _quantize_percent(raw_percent)
128
  filled = int(percent // 5)
129
  bar = "█" * filled + "░" * (20 - filled)
130
  return (
 
713
 
714
  def build_upload_app() -> gr.Blocks:
715
  with gr.Blocks(title="BirdNET Dataset Uploader") as demo:
716
+ gr.HTML(f"<style>{_SOLID_STATUS_CSS}</style>")
717
  gr.Markdown("# BirdNET Dataset Uploader")
718
  gr.Markdown(
719
  "Start in Dataset Repo (HF) to initialize your project repository with the recommended structure. "
 
767
  segments_upload_resume = gr.Button("Resume", variant="secondary")
768
  segments_upload_cancel = gr.Button("Cancel", variant="stop")
769
  segments_upload_refresh = gr.Button("Refresh Status", variant="secondary")
770
+ segments_upload_status = gr.Markdown(value="ℹ️ Ready", elem_id="segments-upload-status")
771
+ segments_upload_progress = gr.Markdown(
772
+ value="**Progress:** waiting to start",
773
+ elem_id="segments-upload-progress",
774
+ )
775
+ segments_auto_refresh = gr.Timer(value=_STATUS_REFRESH_SECONDS, active=False)
776
  segments_last_status_state = gr.State(value="")
777
  segments_last_progress_state = gr.State(value="")
778
 
 
800
  ingestion_resume = gr.Button("Resume", variant="secondary")
801
  ingestion_cancel = gr.Button("Cancel", variant="stop")
802
  ingestion_refresh = gr.Button("Refresh Status", variant="secondary")
803
+ ingestion_status = gr.Markdown(value="ℹ️ Ready", elem_id="ingestion-status")
804
+ ingestion_progress = gr.Markdown(
805
+ value="**Progress:** waiting to start",
806
+ elem_id="ingestion-progress",
807
+ )
808
+ ingestion_auto_refresh = gr.Timer(value=_STATUS_REFRESH_SECONDS, active=False)
809
  ingestion_last_status_state = gr.State(value="")
810
  ingestion_last_progress_state = gr.State(value="")
811