studyOverflow commited on
Commit
bffee2e
·
verified ·
1 Parent(s): a56a5da

fix: count annotator history from both HF snapshot + local file to survive restarts

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -603,11 +603,30 @@ def mbench_a_start(annotator: str, state: dict):
603
  gr.update(visible=False), gr.update(visible=False),
604
  gr.update(visible=False),
605
  "", "")
606
- # Count how many tasks this annotator has already completed historically
 
 
 
607
  historical_count = sum(
608
  1 for anns in MBENCH_A_COMPLETED.values()
609
  if annotator in anns
610
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
 
612
  # Shuffle task order for this annotator
613
  order = list(range(len(MBENCH_A_TASKS)))
 
603
  gr.update(visible=False), gr.update(visible=False),
604
  gr.update(visible=False),
605
  "", "")
606
+ # Count how many tasks this annotator has already completed.
607
+ # Check both:
608
+ # 1. MBENCH_A_COMPLETED (loaded from HF at startup + updated in-memory during this session)
609
+ # 2. The local annotation file (captures annotations made this session before any push)
610
  historical_count = sum(
611
  1 for anns in MBENCH_A_COMPLETED.values()
612
  if annotator in anns
613
  )
614
+ # Also scan the local file in case this session's annotations haven't been pushed yet
615
+ if ANN_FILE_MBENCH_A.exists():
616
+ with ANN_FILE_MBENCH_A.open() as f:
617
+ for line in f:
618
+ line = line.strip()
619
+ if not line:
620
+ continue
621
+ try:
622
+ r = json.loads(line)
623
+ if r.get("annotator") == annotator and r.get("type") == "pairwise_mbench_a":
624
+ tid = r.get("task_id", "")
625
+ # Only count if not already counted in MBENCH_A_COMPLETED
626
+ if tid in MBENCH_A_TASK_BY_ID and annotator not in MBENCH_A_COMPLETED.get(tid, []):
627
+ historical_count += 1
628
+ except Exception:
629
+ pass
630
 
631
  # Shuffle task order for this annotator
632
  order = list(range(len(MBENCH_A_TASKS)))