Bitsage commited on
Commit
9b56ccc
·
1 Parent(s): edcec85

Fix: Load real-time data from registry API with Shadow Scores

Browse files

- Change PRELOADED_CARDS to use live registry instead of static dataset
- Integrate Shadow Scores from dataset with live observations
- Add proper badge calculation based on real scores
- Filter out test/internal files from display
- Now shows real data with proper Shadow Scores from cron

Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -31,7 +31,7 @@ except ImportError:
31
 
32
 
33
  def load_latest_cards_from_registry() -> List[Dict[str, Any]]:
34
- """Load latest observations from live registry API."""
35
  try:
36
  # Fetch live data from registry
37
  response = requests.get(f"{TPR_API_URL}/api/registry/recent?limit=12", timeout=5)
@@ -39,6 +39,22 @@ def load_latest_cards_from_registry() -> List[Dict[str, Any]]:
39
  data = response.json()
40
  observations = data.get('observations', [])
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # Convert observations to card format
43
  cards = []
44
  for obs in observations:
@@ -46,11 +62,24 @@ def load_latest_cards_from_registry() -> List[Dict[str, Any]]:
46
  target_id = obs.get('target_id', '')
47
  if any(pattern in target_id.lower() for pattern in ['test-', 'crovia-', 'debug-', 'demo-']):
48
  continue
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  cards.append({
51
  "model_id": target_id,
52
- "score": 0, # Will be calculated on analyze
53
- "badge": "UNVERIFIED",
54
  "violations": [],
55
  "author": target_id.split("/")[0] if "/" in target_id else "Unknown",
56
  "downloads": "N/A",
@@ -122,8 +151,8 @@ def load_latest_cards_from_dataset() -> List[Dict[str, Any]]:
122
  return FALLBACK_CARDS
123
 
124
 
125
- # Load cards from dataset (with Shadow Score from oracle_scanner cron)
126
- PRELOADED_CARDS = load_latest_cards_from_dataset()
127
 
128
  NECESSITY_CANON = {
129
  "NEC#1": {"name": "Missing data provenance", "severity": 75},
 
31
 
32
 
33
  def load_latest_cards_from_registry() -> List[Dict[str, Any]]:
34
+ """Load latest observations from live registry API with Shadow Scores."""
35
  try:
36
  # Fetch live data from registry
37
  response = requests.get(f"{TPR_API_URL}/api/registry/recent?limit=12", timeout=5)
 
39
  data = response.json()
40
  observations = data.get('observations', [])
41
 
42
+ # Get Shadow Scores from dataset (updated by cron)
43
+ shadow_scores = {}
44
+ try:
45
+ if HF_AVAILABLE:
46
+ index_path = hf_hub_download(
47
+ repo_id=DATASET_ID,
48
+ filename="badges/index.json",
49
+ repo_type="dataset"
50
+ )
51
+ with open(index_path, 'r') as f:
52
+ badges_data = json.load(f)
53
+ for badge in badges_data.get("badges", []):
54
+ shadow_scores[badge.get("model_id")] = badge.get("score", 0)
55
+ except:
56
+ pass
57
+
58
  # Convert observations to card format
59
  cards = []
60
  for obs in observations:
 
62
  target_id = obs.get('target_id', '')
63
  if any(pattern in target_id.lower() for pattern in ['test-', 'crovia-', 'debug-', 'demo-']):
64
  continue
65
+
66
+ # Get Shadow Score if available
67
+ score = shadow_scores.get(target_id, 0)
68
+
69
+ # Determine badge based on score
70
+ if score >= 90:
71
+ badge = "GOLD"
72
+ elif score >= 70:
73
+ badge = "SILVER"
74
+ elif score >= 50:
75
+ badge = "BRONZE"
76
+ else:
77
+ badge = "UNVERIFIED"
78
 
79
  cards.append({
80
  "model_id": target_id,
81
+ "score": score,
82
+ "badge": badge,
83
  "violations": [],
84
  "author": target_id.split("/")[0] if "/" in target_id else "Unknown",
85
  "downloads": "N/A",
 
151
  return FALLBACK_CARDS
152
 
153
 
154
+ # Load cards from live registry (real-time data)
155
+ PRELOADED_CARDS = load_latest_cards_from_registry()
156
 
157
  NECESSITY_CANON = {
158
  "NEC#1": {"name": "Missing data provenance", "severity": 75},