aidn commited on
Commit
32fca16
Β·
verified Β·
1 Parent(s): 8e006d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -127,6 +127,33 @@ def _dataset_count() -> int:
127
  return len(_fetch_dataset())
128
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  # ── Lokales Leaderboard (schneller Cache fΓΌr UI) ──────────────────────────────
131
 
132
  def _load_lb() -> list:
@@ -180,7 +207,7 @@ def _render_leaderboard() -> str:
180
  <details style="margin-bottom:4px;">
181
  <summary style="font-size:.78rem;color:#555;line-height:1.45;cursor:pointer;
182
  list-style:none;display:flex;align-items:flex-start;gap:6px;">
183
- <span style="color:#0A66C2;font-size:.7rem;margin-top:2px;white-space:nowrap;">β–Ά aufklappen</span>
184
  <span style="color:#555;">{preview}</span>
185
  </summary>
186
  <div style="font-size:.78rem;color:#333;line-height:1.6;margin-top:8px;
 
127
  return len(_fetch_dataset())
128
 
129
 
130
+ def _init_leaderboard():
131
+ """Beim Start: lokalen Cache aus HF Dataset befΓΌllen falls leer."""
132
+ if _load_lb():
133
+ return # lokaler Cache bereits vorhanden
134
+ entries = _fetch_dataset()
135
+ if not entries:
136
+ return
137
+ lb = []
138
+ for e in entries:
139
+ metrics = e.get("metrics", [])
140
+ total = e.get("total_score", sum(int(m.get("score", 0)) for m in metrics))
141
+ max_s = e.get("max_score", len(metrics) * 10)
142
+ lb.append({
143
+ "text": e.get("post_text", "").strip(),
144
+ "total": total,
145
+ "max": max_s,
146
+ "pct": e.get("pct", round(total / max_s * 100) if max_s else 0),
147
+ "verdict": e.get("verdict", ""),
148
+ "date": e.get("timestamp", "")[:10],
149
+ })
150
+ _save_lb(lb)
151
+
152
+
153
+ # ── Leaderboard beim Start initialisieren ─────────────────────────────────────
154
+ _init_leaderboard()
155
+
156
+
157
  # ── Lokales Leaderboard (schneller Cache fΓΌr UI) ──────────────────────────────
158
 
159
  def _load_lb() -> list:
 
207
  <details style="margin-bottom:4px;">
208
  <summary style="font-size:.78rem;color:#555;line-height:1.45;cursor:pointer;
209
  list-style:none;display:flex;align-items:flex-start;gap:6px;">
210
+ <span style="color:#0A66C2;font-size:.7rem;margin-top:2px;white-space:nowrap;">β–Ά </span>
211
  <span style="color:#555;">{preview}</span>
212
  </summary>
213
  <div style="font-size:.78rem;color:#333;line-height:1.6;margin-top:8px;