cdborinstein commited on
Commit
61dab4c
·
1 Parent(s): 60f144c

Skip redundant exports when annotation count unchanged

Browse files
Files changed (1) hide show
  1. backup_to_hub.py +19 -10
backup_to_hub.py CHANGED
@@ -36,6 +36,9 @@ scheduler = CommitScheduler(
36
  token=hf_token,
37
  )
38
 
 
 
 
39
 
40
  def wait_for_argilla():
41
  """Wait for Argilla server to be ready with extended retries."""
@@ -88,16 +91,22 @@ def export_annotations():
88
  annotated = [r for r in records if r.get("responses")]
89
 
90
  if annotated:
91
- export_file = EXPORT_DIR / f"{dataset_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
92
- with scheduler.lock:
93
- with open(export_file, "w") as f:
94
- json.dump({
95
- "dataset": dataset_name,
96
- "exported_at": datetime.now().isoformat(),
97
- "num_annotations": len(annotated),
98
- "records": annotated
99
- }, f, indent=2, default=str)
100
- print(f"Exported {len(annotated)} annotations from {dataset_name}", flush=True)
 
 
 
 
 
 
101
  else:
102
  print(f"No annotations yet in {dataset_name}", flush=True)
103
 
 
36
  token=hf_token,
37
  )
38
 
39
+ # Track annotation counts to avoid redundant exports
40
+ last_annotation_counts = {}
41
+
42
 
43
  def wait_for_argilla():
44
  """Wait for Argilla server to be ready with extended retries."""
 
91
  annotated = [r for r in records if r.get("responses")]
92
 
93
  if annotated:
94
+ count = len(annotated)
95
+ # Only export if annotation count changed
96
+ if count != last_annotation_counts.get(dataset_name):
97
+ export_file = EXPORT_DIR / f"{dataset_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
98
+ with scheduler.lock:
99
+ with open(export_file, "w") as f:
100
+ json.dump({
101
+ "dataset": dataset_name,
102
+ "exported_at": datetime.now().isoformat(),
103
+ "num_annotations": count,
104
+ "records": annotated
105
+ }, f, indent=2, default=str)
106
+ last_annotation_counts[dataset_name] = count
107
+ print(f"Exported {count} annotations from {dataset_name}", flush=True)
108
+ else:
109
+ print(f"No new annotations in {dataset_name} (still {count}), skipping export", flush=True)
110
  else:
111
  print(f"No annotations yet in {dataset_name}", flush=True)
112