priyanka0394 Claude Opus 4.6 (1M context) commited on
Commit
ca5b23e
·
1 Parent(s): 9c28362

fix: Use production API, match real dimension keys, remove mock data

Browse files

Switch to production API (api.trustmodel.ai), update dimension keys to match
real response (bias_safety, context_awareness, etc.), remove mock data fallback,
remove EU AI Act score and score range (N/A in production), hide badge section
until lookup is triggered.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +12 -54
app.py CHANGED
@@ -1,64 +1,32 @@
1
  import gradio as gr
2
  import requests
3
 
4
- API_URL = "https://api-trustmodel.pdxqa.com/api/leaderboards/latest/"
5
  LEADERBOARD_URL = "https://trustmodel.ai/leaderboard"
6
  BADGE_BASE_URL = "https://trustmodel.ai/badge/model"
7
 
8
  DIMENSIONS = [
9
- ("safety", "Bias & Safety"),
10
- ("vulnerability", "Security & Vulnerability"),
11
- ("bias", "Bias Detection"),
12
  ("hallucination", "Hallucination"),
13
- ("holistic_reasoning", "Reasoning"),
14
- ("holistic_programming", "Instruction Adherence"),
15
- ("holistic_creativity", "Context Awareness"),
16
  ("accuracy", "Accuracy"),
17
- ("latency", "Latency"),
18
- ("cost", "Cost"),
 
19
  ]
20
 
21
- # Mock data for development (0-100 scale matching real API) — remove when leaderboard API has data
22
- MOCK_LEADERBOARD = [
23
- {"id": "1", "model": "GPT-4o", "vendor": "OpenAI", "composite_score": 92.67,
24
- "category_scores": {"safety": 88.44, "vulnerability": 96.44, "bias": 90.99, "hallucination": 99.31, "holistic_reasoning": 100.0, "holistic_programming": 87.72, "holistic_creativity": 92.18, "accuracy": 96.59, "latency": 76.26, "cost": 82.14},
25
- "eu_ai_act_score": 91.6, "eu_ai_act_status": "PASS", "total_tests": 920,
26
- "score_distribution": {"min": 77.32, "max": 107.62, "median": 94.99, "std_dev": 14.53}},
27
- {"id": "2", "model": "Claude 3.5 Sonnet", "vendor": "Anthropic", "composite_score": 94.12,
28
- "category_scores": {"safety": 95.10, "vulnerability": 93.20, "bias": 94.80, "hallucination": 96.30, "holistic_reasoning": 98.60, "holistic_programming": 91.00, "holistic_creativity": 93.40, "accuracy": 95.60, "latency": 80.50, "cost": 78.30},
29
- "eu_ai_act_score": 93.7, "eu_ai_act_status": "PASS", "total_tests": 920,
30
- "score_distribution": {"min": 78.30, "max": 108.50, "median": 95.10, "std_dev": 12.80}},
31
- {"id": "3", "model": "Gemini 1.5 Pro", "vendor": "Google", "composite_score": 89.45,
32
- "category_scores": {"safety": 86.00, "vulnerability": 91.50, "bias": 87.60, "hallucination": 92.90, "holistic_reasoning": 95.20, "holistic_programming": 85.70, "holistic_creativity": 88.80, "accuracy": 93.10, "latency": 82.30, "cost": 75.90},
33
- "eu_ai_act_score": 88.2, "eu_ai_act_status": "PASS", "total_tests": 920,
34
- "score_distribution": {"min": 72.50, "max": 103.20, "median": 90.10, "std_dev": 15.20}},
35
- {"id": "4", "model": "Llama 3.1 70B", "vendor": "Meta", "composite_score": 82.30,
36
- "category_scores": {"safety": 78.00, "vulnerability": 84.80, "bias": 80.20, "hallucination": 85.30, "holistic_reasoning": 88.50, "holistic_programming": 79.00, "holistic_creativity": 77.90, "accuracy": 86.40, "latency": 90.10, "cost": 95.20},
37
- "eu_ai_act_score": 80.9, "eu_ai_act_status": "PASS", "total_tests": 920,
38
- "score_distribution": {"min": 65.10, "max": 98.80, "median": 83.20, "std_dev": 16.50}},
39
- {"id": "5", "model": "Mistral Large", "vendor": "Mistral AI", "composite_score": 85.60,
40
- "category_scores": {"safety": 82.60, "vulnerability": 87.20, "bias": 84.30, "hallucination": 88.50, "holistic_reasoning": 90.80, "holistic_programming": 83.30, "holistic_creativity": 82.20, "accuracy": 89.60, "latency": 85.40, "cost": 88.70},
41
- "eu_ai_act_score": 84.5, "eu_ai_act_status": "PASS", "total_tests": 920,
42
- "score_distribution": {"min": 70.50, "max": 101.00, "median": 86.40, "std_dev": 14.90}},
43
- {"id": "6", "model": "Cohere Command R+", "vendor": "Cohere", "composite_score": 78.90,
44
- "category_scores": {"safety": 75.00, "vulnerability": 80.50, "bias": 77.70, "hallucination": 81.90, "holistic_reasoning": 84.20, "holistic_programming": 76.60, "holistic_creativity": 74.50, "accuracy": 82.00, "latency": 88.30, "cost": 91.50},
45
- "eu_ai_act_score": 77.5, "eu_ai_act_status": "NEEDS REVIEW", "total_tests": 920,
46
- "score_distribution": {"min": 60.80, "max": 95.50, "median": 79.80, "std_dev": 17.10}},
47
- ]
48
-
49
-
50
  def fetch_leaderboard():
51
- """Fetch the latest leaderboard data from TrustModel API. Falls back to mock data."""
52
  try:
53
  response = requests.get(API_URL, timeout=10)
54
  response.raise_for_status()
55
  data = response.json()
56
- leaderboard = data.get("leaderboard", [])
57
- if leaderboard:
58
- return leaderboard
59
  except Exception:
60
- pass
61
- return MOCK_LEADERBOARD
62
 
63
 
64
  def get_model_names(leaderboard):
@@ -101,7 +69,6 @@ def lookup_model(model_name, leaderboard):
101
  result = f"## {entry['model']}\n"
102
  result += f"**Vendor:** {entry.get('vendor', 'Unknown')}\n\n"
103
  result += f"### TrustScore: {format_score(composite)}/100 ({trust_level})\n\n"
104
- result += f"**EU AI Act Score:** {format_score(entry.get('eu_ai_act_score', 0))} — {entry.get('eu_ai_act_status', 'N/A')}\n\n"
105
  result += f"**Total Tests:** {entry.get('total_tests', 0)}\n\n"
106
  result += "### Dimension Scores\n\n"
107
  result += "| Dimension | Score |\n|-----------|-------|\n"
@@ -110,10 +77,6 @@ def lookup_model(model_name, leaderboard):
110
  score = scores.get(key)
111
  result += f"| {label} | {format_score(score)} |\n"
112
 
113
- dist = entry.get("score_distribution", {})
114
- if dist:
115
- result += f"\n**Score Range:** {format_score(dist.get('min'))} — {format_score(dist.get('max'))} (median: {format_score(dist.get('median'))})\n"
116
-
117
  slug = entry["model"].lower().replace(" ", "-")
118
  badge_code = f'[![TrustScore](https://trustmodel.ai/badge/model/{slug}.svg)](https://trustmodel.ai/leaderboard)'
119
 
@@ -148,11 +111,6 @@ def compare_models(model_1, model_2, model_3, leaderboard):
148
  result += f" **{format_score(e.get('composite_score', 0))}** |"
149
  result += "\n"
150
 
151
- result += "| **EU AI Act** |"
152
- for e in entries:
153
- result += f" {format_score(e.get('eu_ai_act_score', 0))} |"
154
- result += "\n"
155
-
156
  for key, label in DIMENSIONS:
157
  result += f"| {label} |"
158
  for e in entries:
 
1
  import gradio as gr
2
  import requests
3
 
4
+ API_URL = "https://api.trustmodel.ai/api/leaderboards/latest/"
5
  LEADERBOARD_URL = "https://trustmodel.ai/leaderboard"
6
  BADGE_BASE_URL = "https://trustmodel.ai/badge/model"
7
 
8
  DIMENSIONS = [
9
+ ("bias_safety", "Bias & Safety"),
10
+ ("security_vulnerability", "Security & Vulnerability"),
 
11
  ("hallucination", "Hallucination"),
12
+ ("context_awareness", "Context Awareness"),
13
+ ("instruction_adherence", "Instruction Adherence"),
14
+ ("reasoning", "Reasoning"),
15
  ("accuracy", "Accuracy"),
16
+ ("enterprise_alignment", "Enterprise Alignment"),
17
+ ("specialization", "Specialization"),
18
+ ("cost_latency", "Cost & Latency"),
19
  ]
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def fetch_leaderboard():
22
+ """Fetch the latest leaderboard data from TrustModel API."""
23
  try:
24
  response = requests.get(API_URL, timeout=10)
25
  response.raise_for_status()
26
  data = response.json()
27
+ return data.get("leaderboard", [])
 
 
28
  except Exception:
29
+ return []
 
30
 
31
 
32
  def get_model_names(leaderboard):
 
69
  result = f"## {entry['model']}\n"
70
  result += f"**Vendor:** {entry.get('vendor', 'Unknown')}\n\n"
71
  result += f"### TrustScore: {format_score(composite)}/100 ({trust_level})\n\n"
 
72
  result += f"**Total Tests:** {entry.get('total_tests', 0)}\n\n"
73
  result += "### Dimension Scores\n\n"
74
  result += "| Dimension | Score |\n|-----------|-------|\n"
 
77
  score = scores.get(key)
78
  result += f"| {label} | {format_score(score)} |\n"
79
 
 
 
 
 
80
  slug = entry["model"].lower().replace(" ", "-")
81
  badge_code = f'[![TrustScore](https://trustmodel.ai/badge/model/{slug}.svg)](https://trustmodel.ai/leaderboard)'
82
 
 
111
  result += f" **{format_score(e.get('composite_score', 0))}** |"
112
  result += "\n"
113
 
 
 
 
 
 
114
  for key, label in DIMENSIONS:
115
  result += f"| {label} |"
116
  for e in entries: