ehejin commited on
Commit
06e3420
Β·
1 Parent(s): 350ec72

changed admin screen

Browse files
Files changed (1) hide show
  1. src/app.py +47 -15
src/app.py CHANGED
@@ -13,6 +13,7 @@ HuggingFace Space secrets required:
13
  """
14
  import os
15
  import sys
 
16
  import subprocess
17
  from pathlib import Path
18
 
@@ -109,11 +110,12 @@ from src.ui.screens_preference import screen_pair_intro
109
  def _screen_admin(cfg: dict) -> None:
110
  """
111
  Coverage dashboard β€” visit ?admin=1 to see this.
112
- Shows how many items are covered, reserved, and outstanding per category.
 
113
  """
114
  from src.data import (
115
- _get_accepted_counts, _load_pool, _pool_path,
116
- _load_reservations, _expire_reservations, _data_dir,
117
  )
118
 
119
  st.markdown("## πŸ“Š Study Coverage Dashboard")
@@ -124,32 +126,62 @@ def _screen_admin(cfg: dict) -> None:
124
  )
125
 
126
  if st.button("πŸ”„ Refresh", type="primary"):
127
- # Invalidate completion caches so we re-scan HF
128
- data_dir = _data_dir(cfg)
129
- for f in data_dir.glob("completion_cache*"):
130
- f.unlink()
131
  st.rerun()
132
 
 
 
 
133
  for cat_cfg in cfg["categories"]:
134
  cat = cat_cfg["name"]
135
  pool = _load_pool(str(_pool_path(cat, cfg)))
 
136
 
137
- counts = _get_accepted_counts(cat, cfg)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  reservations = _load_reservations(cfg)
139
  _expire_reservations(reservations)
140
-
141
- total = len(pool)
142
- covered = sum(1 for v in counts.values() if v >= 1)
143
- uncovered = total - covered
144
-
145
- # Items currently reserved but not yet completed
146
  reserved_uncovered = sum(
147
  1 for k, v in reservations.items()
148
- if counts.get(k, 0) == 0
149
  )
 
 
 
150
  truly_uncovered = uncovered - reserved_uncovered
151
 
152
  st.markdown(f"### {cat.capitalize()}")
 
 
153
  col1, col2, col3, col4 = st.columns(4)
154
  col1.metric("Total items", total)
155
  col2.metric("Covered βœ…", covered)
 
13
  """
14
  import os
15
  import sys
16
+ import json
17
  import subprocess
18
  from pathlib import Path
19
 
 
110
  def _screen_admin(cfg: dict) -> None:
111
  """
112
  Coverage dashboard β€” visit ?admin=1 to see this.
113
+ Always scans the HF repo directly β€” ignores local completions cache
114
+ so the count reflects real accepted submissions only.
115
  """
116
  from src.data import (
117
+ _load_pool, _pool_path, _data_dir,
118
+ _load_reservations, _expire_reservations,
119
  )
120
 
121
  st.markdown("## πŸ“Š Study Coverage Dashboard")
 
126
  )
127
 
128
  if st.button("πŸ”„ Refresh", type="primary"):
 
 
 
 
129
  st.rerun()
130
 
131
+ hf_token = cfg.get("hf_token", "")
132
+ output_repo = cfg.get("output_dataset_repo", "")
133
+
134
  for cat_cfg in cfg["categories"]:
135
  cat = cat_cfg["name"]
136
  pool = _load_pool(str(_pool_path(cat, cfg)))
137
+ total = len(pool)
138
 
139
+ # ── Scan HF directly (no cache) ──────────────────────────────────────
140
+ hf_counts = {str(i): 0 for i in range(total)}
141
+ n_json = 0
142
+ if hf_token and output_repo:
143
+ try:
144
+ from huggingface_hub import HfApi
145
+ api = HfApi(token=hf_token)
146
+ files = list(api.list_repo_files(repo_id=output_repo, repo_type="dataset"))
147
+ json_files = [f for f in files if f.startswith("json/") and f.endswith(".json")]
148
+ n_json = len(json_files)
149
+ for filepath in json_files:
150
+ try:
151
+ content = api.hf_hub_download(
152
+ repo_id=output_repo,
153
+ filename=filepath,
154
+ repo_type="dataset",
155
+ token=hf_token,
156
+ )
157
+ with open(content) as f:
158
+ submission = json.load(f)
159
+ for item in submission.get("items", []):
160
+ if item.get("category") != cat:
161
+ continue
162
+ idx = item.get("_pool_index")
163
+ if idx is not None:
164
+ hf_counts[str(idx)] = hf_counts.get(str(idx), 0) + 1
165
+ except Exception as e:
166
+ st.warning(f"Could not parse {filepath}: {e}")
167
+ except Exception as e:
168
+ st.error(f"Could not scan HF repo: {e}")
169
+
170
+ # ── Reservations (active in-progress users) ───────────────────────────
171
  reservations = _load_reservations(cfg)
172
  _expire_reservations(reservations)
 
 
 
 
 
 
173
  reserved_uncovered = sum(
174
  1 for k, v in reservations.items()
175
+ if hf_counts.get(k, 0) == 0
176
  )
177
+
178
+ covered = sum(1 for v in hf_counts.values() if v >= 1)
179
+ uncovered = total - covered
180
  truly_uncovered = uncovered - reserved_uncovered
181
 
182
  st.markdown(f"### {cat.capitalize()}")
183
+ st.caption(f"{n_json} submission file(s) in HF repo")
184
+
185
  col1, col2, col3, col4 = st.columns(4)
186
  col1.metric("Total items", total)
187
  col2.metric("Covered βœ…", covered)