nielsr HF Staff commited on
Commit
68095de
·
verified ·
1 Parent(s): f5684cd

Guard build and publish scripts against wiping the data

Browse files
Files changed (2) hide show
  1. build_data.py +5 -0
  2. publish_dataset.py +9 -0
build_data.py CHANGED
@@ -16,6 +16,7 @@ import json
16
  import os
17
  import shutil
18
  import struct
 
19
 
20
  HERE = os.path.dirname(os.path.abspath(__file__))
21
  ROOT = os.path.dirname(HERE)
@@ -32,6 +33,8 @@ def png_size(path):
32
 
33
 
34
  def main():
 
 
35
  manifest = {}
36
  path = os.path.join(ROOT, "manifest.csv")
37
  if os.path.exists(path):
@@ -58,6 +61,8 @@ def main():
58
  except Exception as e:
59
  skipped.append((os.path.basename(f), repr(e)[:120]))
60
 
 
 
61
  compact = dict(ensure_ascii=False, separators=(",", ":"))
62
  # 1) tiny index for the first paint: just the IDs, enough to shuffle, count and show the first paper
63
  with open(os.path.join(SITE, "index.json"), "w") as out:
 
16
  import os
17
  import shutil
18
  import struct
19
+ import sys
20
 
21
  HERE = os.path.dirname(os.path.abspath(__file__))
22
  ROOT = os.path.dirname(HERE)
 
33
 
34
 
35
  def main():
36
+ if not glob.glob(os.path.join(CLAIMS, "*.json")):
37
+ sys.exit(f"No claim files in {CLAIMS}; nothing written. Run this where the claims folder exists.")
38
  manifest = {}
39
  path = os.path.join(ROOT, "manifest.csv")
40
  if os.path.exists(path):
 
61
  except Exception as e:
62
  skipped.append((os.path.basename(f), repr(e)[:120]))
63
 
64
+ if not papers:
65
+ sys.exit(f"No publishable papers found in {CLAIMS}; nothing written.")
66
  compact = dict(ensure_ascii=False, separators=(",", ":"))
67
  # 1) tiny index for the first paint: just the IDs, enough to shuffle, count and show the first paper
68
  with open(os.path.join(SITE, "index.json"), "w") as out:
publish_dataset.py CHANGED
@@ -3,6 +3,7 @@
3
  Usage (from this folder):
4
  python3 publish_dataset.py # build and upload
5
  python3 publish_dataset.py --no-push # build only
 
6
 
7
  Input: dataset/site/, written by build_data.py and kept up to date by check_pwc.py:
8
  site/index.json list of paper IDs (the Space's first fetch)
@@ -22,6 +23,7 @@ import sys
22
 
23
  from datasets import Dataset, Features, Image, Sequence, Value
24
  from datasets.table import embed_table_storage
 
25
 
26
  HERE = os.path.dirname(os.path.abspath(__file__))
27
  OUT = os.path.join(HERE, "dataset")
@@ -124,6 +126,13 @@ The claims and summaries are condensed from the papers, so check them against th
124
 
125
  def main():
126
  ids = json.load(open(os.path.join(SITE, "index.json")))
 
 
 
 
 
 
 
127
  papers = [json.load(open(os.path.join(SITE, "p", f"{i}.json"))) for i in ids]
128
  missing = [p["id"] for p in papers if not os.path.exists(os.path.join(SITE, p["image"])) or os.path.getsize(os.path.join(SITE, p["image"])) < 500]
129
  if missing:
 
3
  Usage (from this folder):
4
  python3 publish_dataset.py # build and upload
5
  python3 publish_dataset.py --no-push # build only
6
+ python3 publish_dataset.py --allow-shrink # allow dropping more than 10% of the live papers
7
 
8
  Input: dataset/site/, written by build_data.py and kept up to date by check_pwc.py:
9
  site/index.json list of paper IDs (the Space's first fetch)
 
23
 
24
  from datasets import Dataset, Features, Image, Sequence, Value
25
  from datasets.table import embed_table_storage
26
+ from huggingface_hub import hf_hub_download
27
 
28
  HERE = os.path.dirname(os.path.abspath(__file__))
29
  OUT = os.path.join(HERE, "dataset")
 
126
 
127
  def main():
128
  ids = json.load(open(os.path.join(SITE, "index.json")))
129
+ if not ids:
130
+ sys.exit("dataset/site/index.json is empty; refusing to publish (it would empty the live dataset and the Space).")
131
+ if "--no-push" not in sys.argv and "--allow-shrink" not in sys.argv:
132
+ live = json.load(open(hf_hub_download(REPO, "site/index.json", repo_type="dataset")))
133
+ if len(ids) < 0.9 * len(live):
134
+ sys.exit(f"Local data has {len(ids)} papers but the live dataset has {len(live)}; "
135
+ "refusing to publish. Pass --allow-shrink if that is intended.")
136
  papers = [json.load(open(os.path.join(SITE, "p", f"{i}.json"))) for i in ids]
137
  missing = [p["id"] for p in papers if not os.path.exists(os.path.join(SITE, p["image"])) or os.path.getsize(os.path.join(SITE, p["image"])) < 500]
138
  if missing: