SChodavarpu commited on
Commit
7c0ed8e
·
verified ·
1 Parent(s): 1b5f299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -69
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.3 — clinical + operational cards)
7
- - Minimal inputs (4 fields). All other assumptions hidden as internal state.
8
  - Four output cards: Overall Impact, Financial, Clinical, Operational.
9
- - HTML waterfall (no matplotlib). CSV only on click. No sticky UI.
 
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 += f"""
236
- <div class='bar'>
237
- <div class='bar-label'>{lab}</div>
238
- <div class='bar-track'><div class='bar-fill' style='width:{pct}%'></div></div>
239
- </div>"""
240
- return f"""
241
- <div class='card'>
242
- <div class='card-head'>
243
- <div class='card-title'>{title}</div>
244
- <div class='card-sub'>{subtitle}</div>
245
- </div>
246
- <div class='kpi-grid'>{rows}</div>
247
- {bars_html}
248
- </div>"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  overall_html = card(
251
  "Overall Impact",
252
  "Incremental (annual)",
253
  [
254
- ("Incremental revenue", money(incr_revenue), False),
255
- ("Incremental costs", money(incr_costs), False),
256
- ("Operational value", money(incr_ops_value), False),
257
  ("Net impact", money(net_impact), True),
258
- ("ROI % (on AI program)", f"{roi_pct:,.1f}%", True),
259
- ("Months to payback", num(months_to_payback, 1), False),
260
  ],
261
  )
 
 
 
 
 
 
262
 
263
  financial_html = card(
264
  "Financial",
265
  "Incremental economics",
266
  [
267
- ("Incr. revenue", money(incr_revenue), False),
268
- ("Incr. costs", money(incr_costs), False),
269
  ("Net impact", money(net_impact), True),
270
  ("AI program costs", money(ai_program_costs), False),
271
- ("ROI %", f"{roi_pct:,.1f}%", True),
272
- ("Payback (months)", num(months_to_payback, 1), False),
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 = f"Based on your {cases_per_year} AI cases/yr, payback in {num(months_to_payback,1)} months."
 
 
 
 
 
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
- :root { --card-bg:#ffffff; --muted:#6b7280; }
340
- .header { display:flex; align-items:center; justify-content:space-between; padding:12px 0; }
341
- .app-title { font-weight:800; font-size:1.4rem; }
342
- .pill { background:#ecfdf5; color:#065f46; padding:4px 10px; border-radius:999px; font-weight:700; font-size:.85rem; }
343
-
344
- .card { background:var(--card-bg); border-radius:18px; padding:18px; box-shadow:0 8px 24px rgba(0,0,0,.08); border:1px solid #eef2f7; }
345
- .card-head { margin-bottom:8px; display:flex; align-items:baseline; gap:8px; }
346
- .card-title { font-weight:800; font-size:1.05rem; }
347
- .card-sub { color:var(--muted); font-size:.9rem; }
348
- .kpi-grid { display:grid; grid-template-columns:1fr auto; gap:6px 12px; align-items:center; margin-bottom:8px; }
349
- .kpi-row { display:contents; }
350
- .kpi-label { color:#4b5563; }
351
- .kpi-val { font-variant-numeric:tabular-nums; font-weight:600; }
352
- .kpi-val.emph { font-weight:900; font-size:1.06rem; }
353
-
354
- .bar { margin-top:8px; }
355
- .bar-label { font-size:.85rem; color:#374151; margin-bottom:2px; }
356
- .bar-track { background:#f1f5f9; border-radius:999px; height:8px; }
357
- .bar-fill { background:linear-gradient(90deg,#14b8a6,#06b6d4); height:8px; border-radius:999px; }
358
-
359
- .muted { color:var(--muted); }
360
- .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; }
361
- .cta-line { font-weight:700; }
362
- .cta-btn { background:#0ea5e9; color:white; padding:8px 12px; border-radius:10px; text-decoration:none; font-weight:700; }
363
-
364
- /* HTML Waterfall */
365
- .wf { margin-top:8px; }
366
- .wf-row { display:flex; align-items:center; gap:10px; margin:6px 0; }
367
- .wf-label { width:150px; color:#334155; font-size:.9rem; }
368
- .wf-bar { height:10px; border-radius:999px; background:#f1f5f9; flex:1; position:relative; }
369
- .wf-fill.pos { position:absolute; left:0; top:0; bottom:0; border-radius:999px; background:linear-gradient(90deg,#22c55e,#16a34a); }
370
- .wf-fill.neg { position:absolute; right:0; top:0; bottom:0; border-radius:999px; background:linear-gradient(90deg,#ef4444,#dc2626); }
371
- .wf-val { width:120px; text-align:right; font-variant-numeric:tabular-nums; }
372
- """) as demo:
 
 
 
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
- return f"""
463
- <div class='wf-row'>
464
- <div class='wf-label'>{label}</div>
465
- <div class='wf-bar'><div class='wf-fill {cls}' style='width:{pct}%'></div></div>
466
- <div class='wf-val'>${val:,.0f}</div>
467
- </div>"""
 
 
 
 
 
 
 
 
 
 
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)