starfriend commited on
Commit
89895a7
·
verified ·
1 Parent(s): 344a1d5

Upload app.py

Browse files
Files changed (1) hide show
  1. metadata_search/app.py +48 -23
metadata_search/app.py CHANGED
@@ -20,7 +20,8 @@ def _bootstrap_search_data() -> None:
20
  if os.getenv("WATERSCOPE_DATA_BOOTSTRAP", "1").lower() not in {"1", "true", "yes"}:
21
  return
22
 
23
- from huggingface_hub import HfApi, hf_hub_download
 
24
 
25
  repo_id = os.getenv(
26
  "WATERSCOPE_DATASET_REPO",
@@ -31,32 +32,55 @@ def _bootstrap_search_data() -> None:
31
  ).resolve()
32
  data_root.mkdir(parents=True, exist_ok=True)
33
 
34
- print(f"[bootstrap] Inspecting dataset {repo_id}")
 
 
 
 
35
  api = HfApi()
36
- repo_files = api.list_repo_files(repo_id=repo_id, repo_type="dataset")
37
-
38
- wanted = [
39
- path for path in repo_files
40
- if path == "metadata/papers.csv"
41
- or path == "metadata_search_data/qdrant_manifest.json"
42
- or path.startswith("metadata_search_data/qdrant/")
43
- ]
44
-
45
- print(f"[bootstrap] Found {len(wanted)} search-data files")
46
- if not wanted:
47
- raise RuntimeError(
48
- "No search-data files found in Dataset. Expected "
49
- "metadata/papers.csv and metadata_search_data/qdrant/..."
50
- )
51
 
52
- for filename in wanted:
53
- print(f"[bootstrap] Downloading {filename}")
54
- hf_hub_download(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  repo_id=repo_id,
56
  repo_type="dataset",
57
- filename=filename,
58
- local_dir=str(data_root),
59
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  paper_csv = data_root / "metadata" / "papers.csv"
62
  qdrant_path = data_root / "metadata_search_data" / "qdrant"
@@ -75,6 +99,7 @@ def _bootstrap_search_data() -> None:
75
  print(f"[bootstrap] PAPER_CSV={paper_csv}")
76
  print(f"[bootstrap] METADATA_QDRANT_PATH={qdrant_path}")
77
  print(f"[bootstrap] METADATA_QDRANT_MANIFEST={qdrant_manifest}")
 
78
 
79
 
80
  _bootstrap_search_data()
 
20
  if os.getenv("WATERSCOPE_DATA_BOOTSTRAP", "1").lower() not in {"1", "true", "yes"}:
21
  return
22
 
23
+ from huggingface_hub import HfApi, RepoFile, hf_hub_download
24
+ from time import monotonic
25
 
26
  repo_id = os.getenv(
27
  "WATERSCOPE_DATASET_REPO",
 
32
  ).resolve()
33
  data_root.mkdir(parents=True, exist_ok=True)
34
 
35
+ started = monotonic()
36
+
37
+ def log(message: str) -> None:
38
+ print(f"[bootstrap pid={os.getpid()} +{monotonic() - started:.1f}s] {message}", flush=True)
39
+
40
  api = HfApi()
41
+ index_prefix = "metadata_search_data/qdrant/"
42
+ log(f"Starting search-data bootstrap for {repo_id}")
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ def download(filename: str) -> None:
45
+ log(f"Downloading {filename}")
46
+ try:
47
+ hf_hub_download(
48
+ repo_id=repo_id,
49
+ repo_type="dataset",
50
+ filename=filename,
51
+ local_dir=str(data_root),
52
+ )
53
+ except Exception as exc:
54
+ log(f"Download failed for {filename}: {type(exc).__name__}: {exc}")
55
+ raise
56
+ log(f"Ready: {filename}")
57
+
58
+ # Known metadata paths do not require a repository-wide file listing.
59
+ download("metadata/papers.csv")
60
+ download("metadata_search_data/qdrant_manifest.json")
61
+
62
+ log(f"Listing only {index_prefix}")
63
+ try:
64
+ index_files = []
65
+ for entry in api.list_repo_tree(
66
  repo_id=repo_id,
67
  repo_type="dataset",
68
+ path_in_repo=index_prefix.rstrip("/"),
69
+ recursive=True,
70
+ expand=False,
71
+ ):
72
+ if isinstance(entry, RepoFile) and entry.path.startswith(index_prefix):
73
+ index_files.append(entry.path)
74
+ log(f"Found index file: {entry.path}")
75
+ except Exception as exc:
76
+ log(f"Qdrant listing failed: {type(exc).__name__}: {exc}")
77
+ raise
78
+
79
+ if not index_files:
80
+ raise RuntimeError(f"No Qdrant files found in Dataset under {index_prefix}")
81
+ log(f"Found {len(index_files)} Qdrant files; media/PDF/summary folders were not listed")
82
+ for filename in sorted(set(index_files)):
83
+ download(filename)
84
 
85
  paper_csv = data_root / "metadata" / "papers.csv"
86
  qdrant_path = data_root / "metadata_search_data" / "qdrant"
 
99
  print(f"[bootstrap] PAPER_CSV={paper_csv}")
100
  print(f"[bootstrap] METADATA_QDRANT_PATH={qdrant_path}")
101
  print(f"[bootstrap] METADATA_QDRANT_MANIFEST={qdrant_manifest}")
102
+ log("Search-data bootstrap complete")
103
 
104
 
105
  _bootstrap_search_data()