Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,11 @@ from dataclasses import dataclass
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
"""
|
| 6 |
-
CARPL ROI Calculator · FFR-CT AI (v4.
|
| 7 |
-
- Minimal inputs (4 fields).
|
| 8 |
- Four output cards: Overall Impact, Financial, Clinical, Operational.
|
| 9 |
-
- HTML waterfall
|
|
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
# ------------------------- Defaults & Config -------------------------
|
|
@@ -65,6 +66,16 @@ CTA_LABEL = "Book a 15-min walkthrough"
|
|
| 65 |
def _pct(x): return max(0.0, min(100.0, float(x)))
|
| 66 |
def _pos(x): return max(0.0, float(x))
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# ------------------------- Core computation -------------------------
|
| 69 |
def compute_roi(
|
| 70 |
site_type,
|
|
@@ -228,48 +239,82 @@ def compute_roi(
|
|
| 228 |
f"<div class='kpi-row'><span class='kpi-label'>{lab}</span><span class='kpi-val{' emph' if emph else ''}'>{val}</span></div>"
|
| 229 |
for (lab, val, emph) in items
|
| 230 |
)
|
|
|
|
| 231 |
bars_html = ""
|
| 232 |
if bars:
|
| 233 |
for (lab, pct) in bars:
|
| 234 |
pct = max(0, min(100, pct))
|
| 235 |
-
bars_html +=
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
overall_html = card(
|
| 251 |
"Overall Impact",
|
| 252 |
"Incremental (annual)",
|
| 253 |
[
|
| 254 |
-
(
|
| 255 |
-
(
|
| 256 |
-
(
|
| 257 |
("Net impact", money(net_impact), True),
|
| 258 |
-
(
|
| 259 |
-
(
|
| 260 |
],
|
| 261 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
financial_html = card(
|
| 264 |
"Financial",
|
| 265 |
"Incremental economics",
|
| 266 |
[
|
| 267 |
-
(
|
| 268 |
-
(
|
| 269 |
("Net impact", money(net_impact), True),
|
| 270 |
("AI program costs", money(ai_program_costs), False),
|
| 271 |
-
(
|
| 272 |
-
(
|
| 273 |
],
|
| 274 |
)
|
| 275 |
|
|
@@ -317,9 +362,14 @@ def compute_roi(
|
|
| 317 |
</div>
|
| 318 |
"""
|
| 319 |
|
| 320 |
-
# Contextual CTA
|
| 321 |
cases_per_year = int(round(annual_uptake_cases))
|
| 322 |
-
cta_line =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
cta_html = f"""
|
| 324 |
<div class='cta-card'>
|
| 325 |
<div class='cta-line'>{cta_line}</div>
|
|
@@ -336,40 +386,43 @@ def compute_roi(
|
|
| 336 |
# ------------------------- UI -------------------------
|
| 337 |
def build_ui():
|
| 338 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
| 373 |
# Header
|
| 374 |
with gr.Row(elem_classes=["header"]):
|
| 375 |
gr.Markdown("""
|
|
@@ -453,18 +506,28 @@ def build_ui():
|
|
| 453 |
sens_vendor_cost_factor_pct,
|
| 454 |
]
|
| 455 |
|
| 456 |
-
# HTML waterfall (dep-free)
|
| 457 |
def waterfall_html(incr_rev, incr_costs, incr_ops, net):
|
| 458 |
maxv = max(abs(incr_rev), abs(incr_costs), abs(incr_ops), abs(net), 1)
|
| 459 |
def row(label, val):
|
| 460 |
pct = int(abs(val) / maxv * 100)
|
| 461 |
cls = 'pos' if val >= 0 else 'neg'
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
return (
|
| 469 |
"<div class='wf'>"
|
| 470 |
+ row("Incr. Revenue", incr_rev)
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
"""
|
| 6 |
+
CARPL ROI Calculator · FFR-CT AI (v4.4 — Inter + tooltips + labeled bars)
|
| 7 |
+
- Minimal inputs (4 fields). Assumptions hidden as internal state.
|
| 8 |
- Four output cards: Overall Impact, Financial, Clinical, Operational.
|
| 9 |
+
- Inter font, HTML waterfall with inline values, percent labels on mini bars.
|
| 10 |
+
- CSV only on click. No sticky UI.
|
| 11 |
"""
|
| 12 |
|
| 13 |
# ------------------------- Defaults & Config -------------------------
|
|
|
|
| 66 |
def _pct(x): return max(0.0, min(100.0, float(x)))
|
| 67 |
def _pos(x): return max(0.0, float(x))
|
| 68 |
|
| 69 |
+
def tooltip(label: str, tip: str) -> str:
|
| 70 |
+
"""Returns a label with a subtle tooltip (title attribute)."""
|
| 71 |
+
# The ℹ︎ glyph has good cross-platform support; title shows on hover
|
| 72 |
+
return (
|
| 73 |
+
f"<span style='display:inline-flex; align-items:center; gap:6px'>"
|
| 74 |
+
f"{label}"
|
| 75 |
+
f"<span title=\"{tip}\" style='cursor:help; opacity:.75'>ℹ︎</span>"
|
| 76 |
+
f"</span>"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
# ------------------------- Core computation -------------------------
|
| 80 |
def compute_roi(
|
| 81 |
site_type,
|
|
|
|
| 239 |
f"<div class='kpi-row'><span class='kpi-label'>{lab}</span><span class='kpi-val{' emph' if emph else ''}'>{val}</span></div>"
|
| 240 |
for (lab, val, emph) in items
|
| 241 |
)
|
| 242 |
+
# bars with right-aligned % labels
|
| 243 |
bars_html = ""
|
| 244 |
if bars:
|
| 245 |
for (lab, pct) in bars:
|
| 246 |
pct = max(0, min(100, pct))
|
| 247 |
+
bars_html += (
|
| 248 |
+
"<div class='bar'>"
|
| 249 |
+
f"<div class='bar-label' style=\"display:flex;align-items:center;justify-content:space-between;\">"
|
| 250 |
+
f"<span>{lab}</span>"
|
| 251 |
+
f"<span style=\"font-variant-numeric:tabular-nums;\">{pct:.0f}%</span>"
|
| 252 |
+
"</div>"
|
| 253 |
+
"<div class='bar-track'><div class='bar-fill' style='width:"
|
| 254 |
+
f"{pct}%'></div></div></div>"
|
| 255 |
+
)
|
| 256 |
+
return (
|
| 257 |
+
"<div class='card'>"
|
| 258 |
+
"<div class='card-head'>"
|
| 259 |
+
f"<div class='card-title'>{title}</div>"
|
| 260 |
+
f"<div class='card-sub'>{subtitle}</div>"
|
| 261 |
+
"</div>"
|
| 262 |
+
f"<div class='kpi-grid'>{rows}</div>"
|
| 263 |
+
f"{bars_html}"
|
| 264 |
+
"</div>"
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
# Labels with tooltips where it helps
|
| 268 |
+
roi_label_tt = tooltip(
|
| 269 |
+
"ROI % (on AI program)",
|
| 270 |
+
"ROI = Net Impact ÷ (Platform + Per-case vendor costs), annualized."
|
| 271 |
+
)
|
| 272 |
+
payback_label_tt = tooltip(
|
| 273 |
+
"Months to payback",
|
| 274 |
+
"Payback months = (AI program costs ÷ net impact per AI case) ÷ monthly AI cases."
|
| 275 |
+
)
|
| 276 |
+
incr_rev_label_tt = tooltip(
|
| 277 |
+
"Incremental revenue",
|
| 278 |
+
"Additional CCTA+FFR-CT+AI-QPA revenue from AI cohort vs baseline."
|
| 279 |
+
)
|
| 280 |
+
incr_costs_label_tt = tooltip(
|
| 281 |
+
"Incremental costs",
|
| 282 |
+
"Vendor per-case + platform + testing/cath costs in AI cohort minus baseline costs."
|
| 283 |
+
)
|
| 284 |
+
ops_value_label_tt = tooltip(
|
| 285 |
+
"Operational value",
|
| 286 |
+
"Value of faster time-to-decision (bed-hours) + clinician hours saved."
|
| 287 |
+
)
|
| 288 |
|
| 289 |
overall_html = card(
|
| 290 |
"Overall Impact",
|
| 291 |
"Incremental (annual)",
|
| 292 |
[
|
| 293 |
+
(incr_rev_label_tt, money(incr_revenue), False),
|
| 294 |
+
(incr_costs_label_tt, money(incr_costs), False),
|
| 295 |
+
(ops_value_label_tt, money(incr_ops_value), False),
|
| 296 |
("Net impact", money(net_impact), True),
|
| 297 |
+
(roi_label_tt, f"{roi_pct:,.1f}%", True),
|
| 298 |
+
(payback_label_tt, num(months_to_payback, 1), False),
|
| 299 |
],
|
| 300 |
)
|
| 301 |
+
# Inline explanation of payback
|
| 302 |
+
overall_html += (
|
| 303 |
+
"<div class='muted' style='margin-top:4px; font-size:.85rem'>"
|
| 304 |
+
"Payback = (AI program costs ÷ net impact per AI case) ÷ monthly AI cases."
|
| 305 |
+
"</div>"
|
| 306 |
+
)
|
| 307 |
|
| 308 |
financial_html = card(
|
| 309 |
"Financial",
|
| 310 |
"Incremental economics",
|
| 311 |
[
|
| 312 |
+
(incr_rev_label_tt, money(incr_revenue), False),
|
| 313 |
+
(incr_costs_label_tt, money(incr_costs), False),
|
| 314 |
("Net impact", money(net_impact), True),
|
| 315 |
("AI program costs", money(ai_program_costs), False),
|
| 316 |
+
(roi_label_tt, f"{roi_pct:,.1f}%", True),
|
| 317 |
+
(payback_label_tt, num(months_to_payback, 1), False),
|
| 318 |
],
|
| 319 |
)
|
| 320 |
|
|
|
|
| 362 |
</div>
|
| 363 |
"""
|
| 364 |
|
| 365 |
+
# Contextual CTA (richer line)
|
| 366 |
cases_per_year = int(round(annual_uptake_cases))
|
| 367 |
+
cta_line = (
|
| 368 |
+
f"Based on your {cases_per_year:,} AI cases/yr: "
|
| 369 |
+
f"net impact {money(net_impact)}, ROI {roi_pct:,.1f}%, payback {num(months_to_payback,1)} mo; "
|
| 370 |
+
f"avoids ~{int(round(avoided_unnec_ica)):,} diagnostic ICAs & ~{int(round(avoided_additional_tests)):,} extra tests; "
|
| 371 |
+
f"frees ~{int(round(bed_hours_saved)):,} bed-hrs & ~{int(round(clinician_hours_saved)):,} clinician-hrs annually."
|
| 372 |
+
)
|
| 373 |
cta_html = f"""
|
| 374 |
<div class='cta-card'>
|
| 375 |
<div class='cta-line'>{cta_line}</div>
|
|
|
|
| 386 |
# ------------------------- UI -------------------------
|
| 387 |
def build_ui():
|
| 388 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
| 389 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
|
| 390 |
+
|
| 391 |
+
:root { --card-bg:#ffffff; --muted:#6b7280; }
|
| 392 |
+
* { font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji'; }
|
| 393 |
+
|
| 394 |
+
.header { display:flex; align-items:center; justify-content:space-between; padding:12px 0; }
|
| 395 |
+
.app-title { font-weight:800; font-size:1.4rem; }
|
| 396 |
+
.pill { background:#ecfdf5; color:#065f46; padding:4px 10px; border-radius:999px; font-weight:700; font-size:.85rem; }
|
| 397 |
+
|
| 398 |
+
.card { background:var(--card-bg); border-radius:18px; padding:18px; box-shadow:0 8px 24px rgba(0,0,0,.08); border:1px solid #eef2f7; }
|
| 399 |
+
.card-head { margin-bottom:8px; display:flex; align-items:baseline; gap:8px; }
|
| 400 |
+
.card-title { font-weight:800; font-size:1.05rem; }
|
| 401 |
+
.card-sub { color:var(--muted); font-size:.9rem; }
|
| 402 |
+
.kpi-grid { display:grid; grid-template-columns:1fr auto; gap:6px 12px; align-items:center; margin-bottom:8px; }
|
| 403 |
+
.kpi-row { display:contents; }
|
| 404 |
+
.kpi-label { color:#4b5563; }
|
| 405 |
+
.kpi-val { font-variant-numeric:tabular-nums; font-weight:600; }
|
| 406 |
+
.kpi-val.emph { font-weight:900; font-size:1.06rem; }
|
| 407 |
+
|
| 408 |
+
.bar { margin-top:8px; }
|
| 409 |
+
.bar-label { font-size:.85rem; color:#374151; margin-bottom:2px; }
|
| 410 |
+
.bar-track { background:#f1f5f9; border-radius:999px; height:8px; position:relative; overflow:hidden; }
|
| 411 |
+
.bar-fill { background:linear-gradient(90deg,#14b8a6,#06b6d4); height:8px; border-radius:999px; }
|
| 412 |
+
|
| 413 |
+
.muted { color:var(--muted); }
|
| 414 |
+
.cta-card { margin-top:8px; padding:12px; border:1px dashed #d1fae5; border-radius:12px; display:flex; align-items:center; justify-content:space-between; gap:10px; }
|
| 415 |
+
.cta-line { font-weight:700; }
|
| 416 |
+
.cta-btn { background:#0ea5e9; color:white; padding:8px 12px; border-radius:10px; text-decoration:none; font-weight:700; }
|
| 417 |
+
|
| 418 |
+
.wf { margin-top:8px; }
|
| 419 |
+
.wf-row { display:flex; align-items:center; gap:10px; margin:6px 0; }
|
| 420 |
+
.wf-label { width:160px; color:#334155; font-size:.9rem; }
|
| 421 |
+
.wf-bar { height:12px; border-radius:999px; background:#f1f5f9; flex:1; position:relative; overflow:hidden; }
|
| 422 |
+
.wf-fill.pos { position:absolute; left:0; top:0; bottom:0; border-radius:999px; background:linear-gradient(90deg,#22c55e,#16a34a); color:rgba(255,255,255,.95); }
|
| 423 |
+
.wf-fill.neg { position:absolute; right:0; top:0; bottom:0; border-radius:999px; background:linear-gradient(90deg,#ef4444,#dc2626); color:rgba(255,255,255,.95); }
|
| 424 |
+
.wf-val { width:140px; text-align:right; font-variant-numeric:tabular-nums; }
|
| 425 |
+
""") as demo:
|
| 426 |
# Header
|
| 427 |
with gr.Row(elem_classes=["header"]):
|
| 428 |
gr.Markdown("""
|
|
|
|
| 506 |
sens_vendor_cost_factor_pct,
|
| 507 |
]
|
| 508 |
|
| 509 |
+
# HTML waterfall (dep-free) with inline values
|
| 510 |
def waterfall_html(incr_rev, incr_costs, incr_ops, net):
|
| 511 |
maxv = max(abs(incr_rev), abs(incr_costs), abs(incr_ops), abs(net), 1)
|
| 512 |
def row(label, val):
|
| 513 |
pct = int(abs(val) / maxv * 100)
|
| 514 |
cls = 'pos' if val >= 0 else 'neg'
|
| 515 |
+
inner_val = f"${val:,.0f}"
|
| 516 |
+
inner = (
|
| 517 |
+
"<div style='position:absolute;inset:0;display:flex;align-items:center;padding:0 8px;"
|
| 518 |
+
"font-size:.82rem;opacity:.95;'>"
|
| 519 |
+
f"{inner_val}</div>"
|
| 520 |
+
if pct >= 24 else ""
|
| 521 |
+
)
|
| 522 |
+
return (
|
| 523 |
+
"<div class='wf-row'>"
|
| 524 |
+
f"<div class='wf-label'>{label}</div>"
|
| 525 |
+
"<div class='wf-bar'>"
|
| 526 |
+
f"<div class='wf-fill {cls}' style='width:{pct}%'>{inner}</div>"
|
| 527 |
+
"</div>"
|
| 528 |
+
f"<div class='wf-val'>{inner_val}</div>"
|
| 529 |
+
"</div>"
|
| 530 |
+
)
|
| 531 |
return (
|
| 532 |
"<div class='wf'>"
|
| 533 |
+ row("Incr. Revenue", incr_rev)
|