Spaces:
Sleeping
Sleeping
Commit ·
571b306
1
Parent(s): bc967f5
feat: TRUS-588 - Redesign Gradio evaluation space UI
Browse files- Dark navy hero banner matching trustmodel.ai brand theme
- Color-coded dimension score bars (green/blue/orange/red)
- Score hero card with trust level pill
- Visual badge preview with copy-paste markdown
- Compare tab with colored score cards and highlighted best scores
- Fixed footer with hover links
- Auto-lookup on model selection (removed redundant button)
- Updated pills: Free, Foundation Models count, vendor names
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -18,8 +18,217 @@ DIMENSIONS = [
|
|
| 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()
|
|
@@ -30,61 +239,86 @@ def fetch_leaderboard():
|
|
| 30 |
|
| 31 |
|
| 32 |
def get_model_names(leaderboard):
|
| 33 |
-
"""Extract model names from leaderboard data."""
|
| 34 |
return [entry["model"] for entry in leaderboard]
|
| 35 |
|
| 36 |
|
| 37 |
def format_score(score):
|
| 38 |
-
"""Format score to one decimal place."""
|
| 39 |
if score is None:
|
| 40 |
return "N/A"
|
| 41 |
return f"{score:.1f}"
|
| 42 |
|
| 43 |
|
| 44 |
def get_trust_level(score):
|
| 45 |
-
"""Get trust level label based on composite score (0-100 scale)."""
|
| 46 |
if score >= 90:
|
| 47 |
-
return "Highly Trusted"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
elif score >= 75:
|
| 49 |
-
return "
|
| 50 |
elif score >= 60:
|
| 51 |
-
return "
|
| 52 |
else:
|
| 53 |
-
return "
|
| 54 |
|
| 55 |
|
| 56 |
def lookup_model(model_name, leaderboard):
|
| 57 |
-
"""Look up a single model and return formatted results + badge code."""
|
| 58 |
if not model_name:
|
| 59 |
-
return "Please select a model.", ""
|
| 60 |
|
| 61 |
entry = next((e for e in leaderboard if e["model"] == model_name), None)
|
| 62 |
if not entry:
|
| 63 |
-
return "Model not found.", ""
|
| 64 |
|
| 65 |
scores = entry.get("category_scores", {})
|
| 66 |
composite = entry.get("composite_score", 0)
|
| 67 |
-
trust_level = get_trust_level(composite)
|
| 68 |
-
|
| 69 |
-
|
| 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"
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
for key, label in DIMENSIONS:
|
| 77 |
score = scores.get(key)
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
return result, badge_code
|
| 84 |
|
| 85 |
|
| 86 |
def compare_models(model_1, model_2, model_3, leaderboard):
|
| 87 |
-
"""Compare 2-3 models side by side."""
|
| 88 |
models = [m for m in [model_1, model_2, model_3] if m]
|
| 89 |
if len(models) < 2:
|
| 90 |
return "Please select at least 2 models to compare."
|
|
@@ -98,28 +332,56 @@ def compare_models(model_1, model_2, model_3, leaderboard):
|
|
| 98 |
if len(entries) < 2:
|
| 99 |
return "Could not find selected models."
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
for e in entries:
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
result += header + "\n" + separator + "\n"
|
| 108 |
|
| 109 |
-
result += "
|
|
|
|
| 110 |
for e in entries:
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
|
| 114 |
for key, label in DIMENSIONS:
|
| 115 |
-
|
| 116 |
for e in entries:
|
| 117 |
score = e.get("category_scores", {}).get(key)
|
| 118 |
-
|
| 119 |
-
result += "\n"
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
return result
|
| 125 |
|
|
@@ -127,70 +389,93 @@ def compare_models(model_1, model_2, model_3, leaderboard):
|
|
| 127 |
# Fetch leaderboard data on startup
|
| 128 |
leaderboard_data = fetch_leaderboard()
|
| 129 |
model_names = get_model_names(leaderboard_data)
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
with gr.Tab("Model Lookup"):
|
| 145 |
-
gr.Markdown("
|
|
|
|
| 146 |
model_dropdown = gr.Dropdown(
|
| 147 |
choices=model_names,
|
| 148 |
label="Select a Model",
|
| 149 |
interactive=True,
|
| 150 |
)
|
| 151 |
-
|
| 152 |
-
result_md = gr.
|
|
|
|
| 153 |
badge_section = gr.Column(visible=False)
|
| 154 |
with badge_section:
|
| 155 |
-
gr.Markdown("### Add
|
| 156 |
badge_code = gr.Code(
|
| 157 |
-
label="
|
| 158 |
language=None,
|
| 159 |
interactive=False,
|
| 160 |
)
|
| 161 |
-
gr.
|
| 162 |
|
| 163 |
def on_lookup(model_name):
|
| 164 |
-
result, badge = lookup_model(model_name, leaderboard_data)
|
| 165 |
show = bool(badge)
|
| 166 |
return result, badge, gr.update(visible=show)
|
| 167 |
|
| 168 |
-
|
| 169 |
fn=on_lookup,
|
| 170 |
inputs=[model_dropdown],
|
| 171 |
outputs=[result_md, badge_code, badge_section],
|
| 172 |
)
|
| 173 |
|
| 174 |
with gr.Tab("Compare Models"):
|
| 175 |
-
gr.Markdown("
|
|
|
|
| 176 |
with gr.Row():
|
| 177 |
compare_1 = gr.Dropdown(choices=model_names, label="Model 1", interactive=True)
|
| 178 |
compare_2 = gr.Dropdown(choices=model_names, label="Model 2", interactive=True)
|
| 179 |
-
compare_3 = gr.Dropdown(choices=model_names, label="Model 3
|
|
|
|
| 180 |
compare_btn = gr.Button("Compare Models", variant="primary")
|
| 181 |
-
compare_result = gr.
|
| 182 |
compare_btn.click(
|
| 183 |
fn=lambda m1, m2, m3: compare_models(m1, m2, m3, leaderboard_data),
|
| 184 |
inputs=[compare_1, compare_2, compare_3],
|
| 185 |
outputs=[compare_result],
|
| 186 |
)
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
("cost_latency", "Cost & Latency"),
|
| 19 |
]
|
| 20 |
|
| 21 |
+
# Generate CSS classes for every possible bar width (0-100) and each color
|
| 22 |
+
BAR_COLORS = {
|
| 23 |
+
"green-hi": "#059669",
|
| 24 |
+
"green": "#10b981",
|
| 25 |
+
"yellow": "#f59e0b",
|
| 26 |
+
"red": "#ef4444",
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
bar_width_css = ""
|
| 30 |
+
for w in range(101):
|
| 31 |
+
bar_width_css += f".bar-w-{w} {{ width: {w}% !important; }}\n"
|
| 32 |
+
|
| 33 |
+
bar_color_css = ""
|
| 34 |
+
for name, hex_val in BAR_COLORS.items():
|
| 35 |
+
bar_color_css += f".bar-{name} {{ background-color: {hex_val} !important; }}\n"
|
| 36 |
+
|
| 37 |
+
CUSTOM_CSS = f"""
|
| 38 |
+
{bar_width_css}
|
| 39 |
+
{bar_color_css}
|
| 40 |
+
|
| 41 |
+
.header-banner {{
|
| 42 |
+
background: linear-gradient(180deg, hsl(210,55%,12%) 0%, hsl(210,50%,18%) 50%, hsl(210,55%,14%) 100%);
|
| 43 |
+
border-radius: 16px;
|
| 44 |
+
padding: 40px 32px;
|
| 45 |
+
margin-bottom: 8px;
|
| 46 |
+
text-align: center;
|
| 47 |
+
position: relative;
|
| 48 |
+
overflow: hidden;
|
| 49 |
+
}}
|
| 50 |
+
.header-banner::before {{
|
| 51 |
+
content: '';
|
| 52 |
+
position: absolute;
|
| 53 |
+
inset: 0;
|
| 54 |
+
background: radial-gradient(ellipse at center, hsla(190,100%,50%,0.08) 0%, transparent 70%);
|
| 55 |
+
pointer-events: none;
|
| 56 |
+
}}
|
| 57 |
+
.header-banner h1 {{
|
| 58 |
+
color: #fff !important;
|
| 59 |
+
font-size: 1.8rem !important;
|
| 60 |
+
margin: 0 0 8px 0 !important;
|
| 61 |
+
font-weight: 800 !important;
|
| 62 |
+
position: relative;
|
| 63 |
+
}}
|
| 64 |
+
.header-banner p {{
|
| 65 |
+
color: rgba(255,255,255,0.6) !important;
|
| 66 |
+
font-size: 0.95rem !important;
|
| 67 |
+
margin: 0 !important;
|
| 68 |
+
position: relative;
|
| 69 |
+
}}
|
| 70 |
+
.header-banner a {{
|
| 71 |
+
color: hsl(190,100%,60%) !important;
|
| 72 |
+
text-decoration: none !important;
|
| 73 |
+
font-weight: 600 !important;
|
| 74 |
+
}}
|
| 75 |
+
.header-banner a:hover {{
|
| 76 |
+
text-decoration: underline !important;
|
| 77 |
+
}}
|
| 78 |
+
.stat-row {{
|
| 79 |
+
display: flex;
|
| 80 |
+
gap: 10px;
|
| 81 |
+
justify-content: center;
|
| 82 |
+
margin-top: 20px;
|
| 83 |
+
flex-wrap: wrap;
|
| 84 |
+
position: relative;
|
| 85 |
+
}}
|
| 86 |
+
.stat-pill {{
|
| 87 |
+
background: rgba(255,255,255,0.08);
|
| 88 |
+
border: 1px solid rgba(255,255,255,0.15);
|
| 89 |
+
border-radius: 20px;
|
| 90 |
+
padding: 5px 14px;
|
| 91 |
+
color: rgba(255,255,255,0.8);
|
| 92 |
+
font-size: 0.75rem;
|
| 93 |
+
font-weight: 500;
|
| 94 |
+
}}
|
| 95 |
+
.score-hero {{
|
| 96 |
+
text-align: center;
|
| 97 |
+
padding: 24px;
|
| 98 |
+
border-radius: 12px;
|
| 99 |
+
background: linear-gradient(135deg, #f0fdf4 0%, #ecfeff 100%);
|
| 100 |
+
border: 1px solid #d1fae5;
|
| 101 |
+
margin: 12px 0;
|
| 102 |
+
}}
|
| 103 |
+
.score-value {{
|
| 104 |
+
font-size: 3rem !important;
|
| 105 |
+
font-weight: 800 !important;
|
| 106 |
+
color: #059669 !important;
|
| 107 |
+
line-height: 1 !important;
|
| 108 |
+
}}
|
| 109 |
+
.score-label {{
|
| 110 |
+
font-size: 1rem !important;
|
| 111 |
+
color: #6b7280 !important;
|
| 112 |
+
margin-top: 4px !important;
|
| 113 |
+
}}
|
| 114 |
+
.trust-level {{
|
| 115 |
+
display: inline-block;
|
| 116 |
+
margin-top: 8px;
|
| 117 |
+
padding: 4px 14px;
|
| 118 |
+
border-radius: 20px;
|
| 119 |
+
font-size: 0.85rem;
|
| 120 |
+
font-weight: 600;
|
| 121 |
+
}}
|
| 122 |
+
.level-safe {{ background: #d1fae5 !important; color: #065f46 !important; }}
|
| 123 |
+
.level-trusted {{ background: #a7f3d0 !important; color: #064e3b !important; }}
|
| 124 |
+
.level-caution {{ background: #fef3c7 !important; color: #92400e !important; }}
|
| 125 |
+
.level-risk {{ background: #fee2e2 !important; color: #991b1b !important; }}
|
| 126 |
+
.dimension-bar {{
|
| 127 |
+
display: flex;
|
| 128 |
+
align-items: center;
|
| 129 |
+
gap: 12px;
|
| 130 |
+
padding: 6px 0;
|
| 131 |
+
}}
|
| 132 |
+
.dim-label {{
|
| 133 |
+
width: 180px;
|
| 134 |
+
font-size: 0.85rem !important;
|
| 135 |
+
color: #374151 !important;
|
| 136 |
+
font-weight: 500 !important;
|
| 137 |
+
text-align: right;
|
| 138 |
+
flex-shrink: 0;
|
| 139 |
+
}}
|
| 140 |
+
.dim-track {{
|
| 141 |
+
flex: 1;
|
| 142 |
+
height: 10px;
|
| 143 |
+
background: #e5e7eb !important;
|
| 144 |
+
border-radius: 5px;
|
| 145 |
+
overflow: hidden;
|
| 146 |
+
}}
|
| 147 |
+
.dim-fill {{
|
| 148 |
+
height: 100%;
|
| 149 |
+
border-radius: 5px;
|
| 150 |
+
}}
|
| 151 |
+
.dim-score {{
|
| 152 |
+
width: 45px;
|
| 153 |
+
font-size: 0.8rem !important;
|
| 154 |
+
color: #6b7280 !important;
|
| 155 |
+
font-weight: 600 !important;
|
| 156 |
+
}}
|
| 157 |
+
.badge-card {{
|
| 158 |
+
background: #f8fafc;
|
| 159 |
+
border: 2px dashed #cbd5e1;
|
| 160 |
+
border-radius: 12px;
|
| 161 |
+
padding: 20px;
|
| 162 |
+
text-align: center;
|
| 163 |
+
margin: 12px 0;
|
| 164 |
+
}}
|
| 165 |
+
.badge-card img {{
|
| 166 |
+
margin: 12px auto;
|
| 167 |
+
display: block;
|
| 168 |
+
}}
|
| 169 |
+
.badge-label {{
|
| 170 |
+
font-size: 0.85rem !important;
|
| 171 |
+
color: #64748b !important;
|
| 172 |
+
margin-bottom: 8px;
|
| 173 |
+
font-weight: 600 !important;
|
| 174 |
+
}}
|
| 175 |
+
.badge-hint {{
|
| 176 |
+
font-size: 0.75rem !important;
|
| 177 |
+
color: #94a3b8 !important;
|
| 178 |
+
margin-top: 8px;
|
| 179 |
+
}}
|
| 180 |
+
.footer-bar {{
|
| 181 |
+
text-align: center;
|
| 182 |
+
padding: 16px;
|
| 183 |
+
margin-top: 8px;
|
| 184 |
+
font-size: 0.8rem;
|
| 185 |
+
color: #9ca3af;
|
| 186 |
+
}}
|
| 187 |
+
.footer-bar a {{
|
| 188 |
+
color: #6b7280 !important;
|
| 189 |
+
text-decoration: none !important;
|
| 190 |
+
margin: 0 8px;
|
| 191 |
+
}}
|
| 192 |
+
.footer-bar a:hover {{
|
| 193 |
+
color: #0ea5e9 !important;
|
| 194 |
+
}}
|
| 195 |
+
.footer-link {{
|
| 196 |
+
font-size: 0.75rem !important;
|
| 197 |
+
color: #94a3b8 !important;
|
| 198 |
+
text-decoration: none !important;
|
| 199 |
+
font-weight: 500 !important;
|
| 200 |
+
transition: color 0.2s ease !important;
|
| 201 |
+
}}
|
| 202 |
+
.footer-link:hover {{
|
| 203 |
+
color: #0ea5e9 !important;
|
| 204 |
+
}}
|
| 205 |
+
.lookup-row {{
|
| 206 |
+
display: flex;
|
| 207 |
+
align-items: flex-end !important;
|
| 208 |
+
gap: 12px;
|
| 209 |
+
}}
|
| 210 |
+
.compare-card {{
|
| 211 |
+
text-align: center;
|
| 212 |
+
padding: 16px 24px;
|
| 213 |
+
border-radius: 12px;
|
| 214 |
+
background: #f8fafc;
|
| 215 |
+
border: 1px solid #e2e8f0;
|
| 216 |
+
min-width: 160px;
|
| 217 |
+
}}
|
| 218 |
+
.compare-score {{
|
| 219 |
+
font-size: 2rem !important;
|
| 220 |
+
font-weight: 800 !important;
|
| 221 |
+
color: #059669 !important;
|
| 222 |
+
}}
|
| 223 |
+
.compare-name {{
|
| 224 |
+
font-size: 0.8rem !important;
|
| 225 |
+
color: #64748b !important;
|
| 226 |
+
font-weight: 600 !important;
|
| 227 |
+
}}
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
|
| 231 |
def fetch_leaderboard():
|
|
|
|
| 232 |
try:
|
| 233 |
response = requests.get(API_URL, timeout=10)
|
| 234 |
response.raise_for_status()
|
|
|
|
| 239 |
|
| 240 |
|
| 241 |
def get_model_names(leaderboard):
|
|
|
|
| 242 |
return [entry["model"] for entry in leaderboard]
|
| 243 |
|
| 244 |
|
| 245 |
def format_score(score):
|
|
|
|
| 246 |
if score is None:
|
| 247 |
return "N/A"
|
| 248 |
return f"{score:.1f}"
|
| 249 |
|
| 250 |
|
| 251 |
def get_trust_level(score):
|
|
|
|
| 252 |
if score >= 90:
|
| 253 |
+
return "Highly Trusted", "level-trusted"
|
| 254 |
+
elif score >= 75:
|
| 255 |
+
return "Generally Safe", "level-safe"
|
| 256 |
+
elif score >= 60:
|
| 257 |
+
return "Use with Caution", "level-caution"
|
| 258 |
+
else:
|
| 259 |
+
return "High Risk", "level-risk"
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def get_bar_color_hex(score):
|
| 263 |
+
if score >= 90:
|
| 264 |
+
return "#22c55e"
|
| 265 |
elif score >= 75:
|
| 266 |
+
return "#3b82f6"
|
| 267 |
elif score >= 60:
|
| 268 |
+
return "#f97316"
|
| 269 |
else:
|
| 270 |
+
return "#ef4444"
|
| 271 |
|
| 272 |
|
| 273 |
def lookup_model(model_name, leaderboard):
|
|
|
|
| 274 |
if not model_name:
|
| 275 |
+
return "Please select a model.", "", ""
|
| 276 |
|
| 277 |
entry = next((e for e in leaderboard if e["model"] == model_name), None)
|
| 278 |
if not entry:
|
| 279 |
+
return "Model not found.", "", ""
|
| 280 |
|
| 281 |
scores = entry.get("category_scores", {})
|
| 282 |
composite = entry.get("composite_score", 0)
|
| 283 |
+
trust_level, level_class = get_trust_level(composite)
|
| 284 |
+
vendor = entry.get("vendor", "Unknown")
|
| 285 |
+
total_tests = entry.get("total_tests", 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
+
slug = entry["model"].lower().replace(" ", "-").replace("(", "").replace(")", "")
|
| 288 |
+
badge_url = f"{BADGE_BASE_URL}/{slug}.svg"
|
| 289 |
+
badge_code = f'[](https://trustmodel.ai/leaderboard)'
|
| 290 |
+
|
| 291 |
+
# Score hero
|
| 292 |
+
result = f"""<div class="score-hero">
|
| 293 |
+
<div class="score-value">{format_score(composite)}</div>
|
| 294 |
+
<div class="score-label">out of 100 · {vendor} · {total_tests} tests</div>
|
| 295 |
+
<div class="trust-level {level_class}">{trust_level}</div>
|
| 296 |
+
</div>\n\n"""
|
| 297 |
+
|
| 298 |
+
# Dimension bars with inline styles
|
| 299 |
+
result += "<h3>Dimension Scores</h3>\n"
|
| 300 |
for key, label in DIMENSIONS:
|
| 301 |
score = scores.get(key)
|
| 302 |
+
if score is not None:
|
| 303 |
+
color = get_bar_color_hex(score)
|
| 304 |
+
w = int(round(score))
|
| 305 |
+
result += f'''<div style="display:flex;align-items:center;gap:12px;padding:6px 0;">
|
| 306 |
+
<span style="width:180px;font-size:0.85rem;color:#374151;font-weight:500;text-align:right;flex-shrink:0;">{label}</span>
|
| 307 |
+
<span style="flex:1;height:10px;background:#e5e7eb;border-radius:5px;overflow:hidden;"><span style="display:block;height:100%;width:{w}%;background-color:{color};border-radius:5px;"></span></span>
|
| 308 |
+
<span style="width:45px;font-size:0.8rem;color:#6b7280;font-weight:600;">{score:.1f}</span>
|
| 309 |
+
</div>\n'''
|
| 310 |
|
| 311 |
+
# Badge preview
|
| 312 |
+
result += f"""\n<div class="badge-card">
|
| 313 |
+
<div class="badge-label">Badge Preview</div>
|
| 314 |
+
<a href="https://trustmodel.ai/leaderboard"><img src="{badge_url}" alt="TrustScore: {format_score(composite/10)}/10"></a>
|
| 315 |
+
<div class="badge-hint">Copy the markdown below to add this badge to your model card</div>
|
| 316 |
+
</div>"""
|
| 317 |
|
| 318 |
+
return result, badge_code, badge_url
|
| 319 |
|
| 320 |
|
| 321 |
def compare_models(model_1, model_2, model_3, leaderboard):
|
|
|
|
| 322 |
models = [m for m in [model_1, model_2, model_3] if m]
|
| 323 |
if len(models) < 2:
|
| 324 |
return "Please select at least 2 models to compare."
|
|
|
|
| 332 |
if len(entries) < 2:
|
| 333 |
return "Could not find selected models."
|
| 334 |
|
| 335 |
+
# Score cards
|
| 336 |
+
result = '<div style="display:flex;gap:16px;justify-content:center;margin-bottom:20px;flex-wrap:wrap;">'
|
| 337 |
+
for e in entries:
|
| 338 |
+
composite = e.get("composite_score", 0)
|
| 339 |
+
trust_level, level_class = get_trust_level(composite)
|
| 340 |
+
score_color = get_bar_color_hex(composite)
|
| 341 |
+
result += f"""<div style="text-align:center;padding:16px 24px;border-radius:12px;background:#f8fafc;border:1px solid #e2e8f0;min-width:160px;">
|
| 342 |
+
<div style="font-size:0.8rem;color:#64748b;font-weight:600;">{e['model']}</div>
|
| 343 |
+
<div style="font-size:2rem;font-weight:800;color:{score_color};">{format_score(composite)}</div>
|
| 344 |
+
<span class="trust-level {level_class}">{trust_level}</span>
|
| 345 |
+
</div>"""
|
| 346 |
+
result += "</div>\n\n"
|
| 347 |
+
|
| 348 |
+
# Comparison table as HTML
|
| 349 |
+
result += '<h3>Dimension Comparison</h3>'
|
| 350 |
+
result += '<table style="width:100%;border-collapse:collapse;font-size:0.85rem;margin-top:12px;">'
|
| 351 |
+
result += '<thead><tr style="border-bottom:2px solid #e2e8f0;text-align:left;">'
|
| 352 |
+
result += '<th style="padding:8px 12px;">Dimension</th>'
|
| 353 |
for e in entries:
|
| 354 |
+
result += f'<th style="padding:8px 12px;text-align:center;">{e["model"]}</th>'
|
| 355 |
+
result += '</tr></thead><tbody>'
|
|
|
|
| 356 |
|
| 357 |
+
result += '<tr style="background:#f0fdf4;font-weight:700;border-bottom:1px solid #e2e8f0;">'
|
| 358 |
+
result += '<td style="padding:8px 12px;">TrustScore</td>'
|
| 359 |
for e in entries:
|
| 360 |
+
cs = e.get("composite_score", 0)
|
| 361 |
+
result += f'<td style="padding:8px 12px;text-align:center;color:{get_bar_color_hex(cs)};">{format_score(cs)}</td>'
|
| 362 |
+
result += '</tr>'
|
| 363 |
|
| 364 |
for key, label in DIMENSIONS:
|
| 365 |
+
scores_list = []
|
| 366 |
for e in entries:
|
| 367 |
score = e.get("category_scores", {}).get(key)
|
| 368 |
+
scores_list.append(score)
|
|
|
|
| 369 |
|
| 370 |
+
best = max((s for s in scores_list if s is not None), default=None)
|
| 371 |
+
|
| 372 |
+
result += '<tr style="border-bottom:1px solid #f1f5f9;">'
|
| 373 |
+
result += f'<td style="padding:8px 12px;color:#374151;">{label}</td>'
|
| 374 |
+
for score in scores_list:
|
| 375 |
+
color = get_bar_color_hex(score) if score is not None else "#6b7280"
|
| 376 |
+
is_best = score is not None and score == best and len(entries) > 1
|
| 377 |
+
weight = "700" if is_best else "600"
|
| 378 |
+
result += f'<td style="padding:8px 12px;text-align:center;font-weight:{weight};color:{color};">{format_score(score)}</td>'
|
| 379 |
+
result += '</tr>'
|
| 380 |
+
|
| 381 |
+
result += '</tbody></table>'
|
| 382 |
+
|
| 383 |
+
best_entry = max(entries, key=lambda e: e.get("composite_score", 0))
|
| 384 |
+
result += f'<p style="margin-top:16px;font-weight:700;font-size:0.95rem;">Winner: {best_entry["model"]} with TrustScore {format_score(best_entry.get("composite_score", 0))}/100</p>'
|
| 385 |
|
| 386 |
return result
|
| 387 |
|
|
|
|
| 389 |
# Fetch leaderboard data on startup
|
| 390 |
leaderboard_data = fetch_leaderboard()
|
| 391 |
model_names = get_model_names(leaderboard_data)
|
| 392 |
+
model_count = len(model_names)
|
| 393 |
+
|
| 394 |
+
theme = gr.themes.Soft(
|
| 395 |
+
primary_hue="cyan",
|
| 396 |
+
secondary_hue="blue",
|
| 397 |
+
neutral_hue="slate",
|
| 398 |
+
font=("Inter", "system-ui", "sans-serif"),
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
with gr.Blocks(title="TrustModel — AI Evaluation", css=CUSTOM_CSS, theme=theme) as demo:
|
| 402 |
+
|
| 403 |
+
# Header
|
| 404 |
+
gr.HTML(f"""<div class="header-banner">
|
| 405 |
+
<h1>TrustModel — AI Evaluation</h1>
|
| 406 |
+
<p>Look up TrustScores, compare AI models, and get badge embed code for your model card.</p>
|
| 407 |
+
<div class="stat-row">
|
| 408 |
+
<span class="stat-pill">Free — No Account Needed</span>
|
| 409 |
+
<span class="stat-pill">{model_count} Foundation Models</span>
|
| 410 |
+
<span class="stat-pill">OpenAI · Google · Anthropic · Meta · MistralAI</span>
|
| 411 |
+
</div>
|
| 412 |
+
<p style="margin-top:12px !important;font-size:0.85rem !important;">
|
| 413 |
+
<a href="https://trustmodel.ai">TrustModel.ai</a>
|
| 414 |
+
<a href="https://trustmodel.ai/developers">API & SDKs</a> ·
|
| 415 |
+
<a href="https://trustmodel.ai/leaderboard">Full Leaderboard</a> ·
|
| 416 |
+
</p>
|
| 417 |
+
</div>""")
|
| 418 |
|
| 419 |
with gr.Tab("Model Lookup"):
|
| 420 |
+
gr.Markdown("Select a model to view its TrustScore across all 10 trust dimensions and get a badge for your model card.")
|
| 421 |
+
|
| 422 |
model_dropdown = gr.Dropdown(
|
| 423 |
choices=model_names,
|
| 424 |
label="Select a Model",
|
| 425 |
interactive=True,
|
| 426 |
)
|
| 427 |
+
|
| 428 |
+
result_md = gr.HTML()
|
| 429 |
+
|
| 430 |
badge_section = gr.Column(visible=False)
|
| 431 |
with badge_section:
|
| 432 |
+
gr.Markdown("### Add to Your Model Card")
|
| 433 |
badge_code = gr.Code(
|
| 434 |
+
label="Copy this markdown and paste into your HuggingFace model card",
|
| 435 |
language=None,
|
| 436 |
interactive=False,
|
| 437 |
)
|
| 438 |
+
gr.HTML('<div style="text-align:center;margin-top:12px;"><a href="https://trustmodel.ai/leaderboard" target="_blank" style="display:inline-block;padding:8px 24px;background:#0ea5e9;color:#fff;border-radius:8px;font-size:0.9rem;font-weight:600;text-decoration:none;">View Full Rankings on TrustModel.ai →</a></div>')
|
| 439 |
|
| 440 |
def on_lookup(model_name):
|
| 441 |
+
result, badge, badge_url = lookup_model(model_name, leaderboard_data)
|
| 442 |
show = bool(badge)
|
| 443 |
return result, badge, gr.update(visible=show)
|
| 444 |
|
| 445 |
+
model_dropdown.change(
|
| 446 |
fn=on_lookup,
|
| 447 |
inputs=[model_dropdown],
|
| 448 |
outputs=[result_md, badge_code, badge_section],
|
| 449 |
)
|
| 450 |
|
| 451 |
with gr.Tab("Compare Models"):
|
| 452 |
+
gr.Markdown("Select 2 or 3 models to compare their TrustScores side by side. Best score per dimension is highlighted.")
|
| 453 |
+
|
| 454 |
with gr.Row():
|
| 455 |
compare_1 = gr.Dropdown(choices=model_names, label="Model 1", interactive=True)
|
| 456 |
compare_2 = gr.Dropdown(choices=model_names, label="Model 2", interactive=True)
|
| 457 |
+
compare_3 = gr.Dropdown(choices=model_names, label="Model 3", interactive=True)
|
| 458 |
+
|
| 459 |
compare_btn = gr.Button("Compare Models", variant="primary")
|
| 460 |
+
compare_result = gr.HTML()
|
| 461 |
compare_btn.click(
|
| 462 |
fn=lambda m1, m2, m3: compare_models(m1, m2, m3, leaderboard_data),
|
| 463 |
inputs=[compare_1, compare_2, compare_3],
|
| 464 |
outputs=[compare_result],
|
| 465 |
)
|
| 466 |
|
| 467 |
+
# Footer
|
| 468 |
+
gr.HTML("""<div style="position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:1px solid #e2e8f0;padding:12px 0;text-align:center;z-index:100;">
|
| 469 |
+
<div style="display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap;">
|
| 470 |
+
<strong style="font-size:0.8rem;color:#334155;">TrustModel Inc.</strong>
|
| 471 |
+
<a href="https://trustmodel.ai" target="_blank" class="footer-link">Website</a>
|
| 472 |
+
<span style="font-size:0.75rem;color:#d1d5db;">·</span>
|
| 473 |
+
<a href="https://trustmodel.ai/leaderboard" target="_blank" class="footer-link">Leaderboard</a>
|
| 474 |
+
<span style="font-size:0.75rem;color:#d1d5db;">·</span>
|
| 475 |
+
<a href="https://trustmodel.ai/developers" target="_blank" class="footer-link">Developers</a>
|
| 476 |
+
<span style="font-size:0.75rem;color:#d1d5db;">·</span>
|
| 477 |
+
<a href="https://trustmodel.ai/contact" target="_blank" class="footer-link">Contact</a>
|
| 478 |
+
</div>
|
| 479 |
+
</div>""")
|
| 480 |
+
|
| 481 |
+
demo.launch(theme=theme)
|