File size: 23,710 Bytes
1b26bd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#!/usr/bin/env python3
"""TenderIQ v5 — Data Forward (PPTX with embedded matplotlib charts)"""
import os
import io
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN

# Palette
BG    = RGBColor(0xFA, 0xFA, 0xFA)
PRI   = RGBColor(0x1E, 0x29, 0x3B)
ACC   = RGBColor(0x63, 0x66, 0xF1)   # indigo
TXT   = RGBColor(0x33, 0x41, 0x55)
TXT2  = RGBColor(0x64, 0x74, 0x8B)
GRD   = RGBColor(0xE2, 0xE8, 0xF0)
GRN   = RGBColor(0x22, 0xC5, 0x5E)
RED_C = RGBColor(0xEF, 0x44, 0x44)
AMB   = RGBColor(0xF5, 0x9E, 0x0B)
BLU   = RGBColor(0x3B, 0x82, 0xF6)
PUR   = RGBColor(0x8B, 0x5C, 0xF6)
FONT  = "Calibri"

HEX = {
    "bg":   "#FAFAFA",
    "pri":  "#1E293B",
    "acc":  "#6366F1",
    "txt":  "#334155",
    "txt2": "#64748B",
    "grd":  "#E2E8F0",
    "grn":  "#22C55E",
    "red":  "#EF4444",
    "amb":  "#F59E0B",
    "blu":  "#3B82F6",
    "pur":  "#8B5CF6",
}


def new_prs():
    prs = Presentation()
    prs.slide_width = Inches(13.33)
    prs.slide_height = Inches(7.5)
    return prs


def blank(prs):
    return prs.slides.add_slide(prs.slide_layouts[6])


def rect(slide, x, y, w, h, fill, line=None, lw=Pt(1)):
    s = slide.shapes.add_shape(1, x, y, w, h)
    s.fill.solid()
    s.fill.fore_color.rgb = fill
    if line:
        s.line.color.rgb = line
        s.line.width = lw
    else:
        s.line.fill.background()
    return s


def txt(slide, text, x, y, w, h, sz=14, bold=False, clr=None, align=PP_ALIGN.LEFT):
    tb = slide.shapes.add_textbox(x, y, w, h)
    tf = tb.text_frame
    tf.word_wrap = True
    p = tf.paragraphs[0]
    p.alignment = align
    r = p.add_run()
    r.text = text
    r.font.size = Pt(sz)
    r.font.bold = bold
    r.font.name = FONT
    if clr:
        r.font.color.rgb = clr
    return tb


def bg(slide):
    rect(slide, 0, 0, Inches(13.33), Inches(7.5), BG)


def heading(slide, text, y=Inches(0.3)):
    rect(slide, Inches(0.6), y + Inches(0.08), Inches(0.06), Inches(0.44), ACC)
    txt(slide, text, Inches(0.8), y, Inches(12.3), Inches(0.6),
        sz=24, bold=True, clr=ACC)


def png_to_slide(slide, fig, x, y, w, h):
    buf = io.BytesIO()
    fig.savefig(buf, format="png", dpi=150, bbox_inches="tight",
                facecolor=HEX["bg"], transparent=True)
    plt.close(fig)
    buf.seek(0)
    slide.shapes.add_picture(buf, x, y, w, h)


def mpl_style():
    plt.rcParams.update({
        "axes.facecolor": HEX["bg"],
        "figure.facecolor": HEX["bg"],
        "axes.edgecolor": HEX["grd"],
        "axes.grid": True,
        "grid.color": HEX["grd"],
        "grid.linewidth": 0.7,
        "text.color": HEX["pri"],
        "xtick.color": HEX["txt2"],
        "ytick.color": HEX["txt2"],
        "font.family": "DejaVu Sans",
    })


# ── Slide 1 ─────────────────────────────────────────────────────────────────
def s1(prs):
    slide = blank(prs)
    bg(slide)
    rect(slide, 0, 0, Inches(0.5), Inches(7.5), ACC)
    txt(slide, "TenderIQ", Inches(0.7), Inches(1.8), Inches(11.5), Inches(1.5),
        sz=64, bold=True, clr=PRI, align=PP_ALIGN.LEFT)
    txt(slide, "Explainable AI for Government Tender Evaluation",
        Inches(0.7), Inches(3.3), Inches(11.5), Inches(0.65),
        sz=22, clr=ACC)
    rect(slide, Inches(0.7), Inches(4.1), Inches(8), Inches(0.05), GRD)
    txt(slide, "CRPF Hackathon  ·  Theme 3",
        Inches(0.7), Inches(4.3), Inches(8), Inches(0.5),
        sz=16, clr=TXT2)
    txt(slide, "From days to minutes. Every decision traceable.",
        Inches(0.7), Inches(4.95), Inches(9), Inches(0.5),
        sz=15, clr=TXT)


# ── Slide 2 ─────────────────────────────────────────────────────────────────
def s2(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "The Problem with Manual Tender Evaluation")
    mpl_style()
    fig, ax = plt.subplots(figsize=(5.5, 3.8))
    categories = ["Manual\nProcess", "TenderIQ"]
    values = [4.0, 0.02]
    colors_ = [HEX["red"], HEX["grn"]]
    bars = ax.bar(categories, values, color=colors_, width=0.45, zorder=3)
    ax.set_ylabel("Days per tender", color=HEX["txt2"], fontsize=11)
    ax.set_ylim(0, 5.5)
    ax.set_title("Evaluation time comparison", color=HEX["pri"], fontsize=12, pad=8)
    for bar, val in zip(bars, values):
        label = f"{val} days" if val >= 0.1 else "Minutes"
        ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.1,
                label, ha="center", va="bottom", fontsize=12,
                fontweight="bold", color=HEX["pri"])
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    ax.tick_params(axis="x", labelsize=12)
    png_to_slide(slide, fig, Inches(0.6), Inches(1.0), Inches(5.8), Inches(4.5))

    bullets = [
        ("3–5 Days", "per tender evaluation by committee"),
        ("Inconsistent", "two evaluators, two conclusions"),
        ("No Audit Trail", "decisions made untraceably"),
    ]
    for i, (big, sub) in enumerate(bullets):
        rect(slide, Inches(7.3), Inches(1.2) + Inches(1.55 * i),
             Inches(5.5), Inches(1.3), RGBColor(0xF1, 0xF5, 0xF9), GRD, Pt(1))
        txt(slide, big, Inches(7.5), Inches(1.3) + Inches(1.55 * i),
            Inches(5.0), Inches(0.55), sz=22, bold=True, clr=ACC)
        txt(slide, sub, Inches(7.5), Inches(1.85) + Inches(1.55 * i),
            Inches(5.0), Inches(0.45), sz=13, clr=TXT)
    txt(slide, ("• Mixed document formats: typed PDFs, scans, phone photographs\n"
                "• Government procurement worth ₹50 lakh crore+ annually in India"),
        Inches(7.3), Inches(6.0), Inches(5.5), Inches(0.9), sz=12, clr=TXT2)


# ── Slide 3 ─────────────────────────────────────────────────────────────────
def s3(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "TenderIQ — Four Stages, End to End")
    stages = [
        ("1", "Extract",
         "DeepSeek LLM reads tender PDF → structured JSON criteria"),
        ("2", "OCR & Index",
         "3-tier pipeline handles any format → vector index"),
        ("3", "Evaluate",
         "Vector search + LLM verdict + safety rule"),
        ("4", "Review & Audit",
         "Human review queue + full exportable audit trail"),
    ]
    cw = Inches(2.8)
    for i, (num, title, body) in enumerate(stages):
        sx = Inches(0.6) + i * Inches(3.18)
        rect(slide, sx, Inches(1.1), cw, Inches(3.5), RGBColor(0xF1, 0xF5, 0xF9), GRD, Pt(1))
        # Number circle (drawn as square for simplicity)
        rect(slide, sx + Inches(0.15), Inches(1.25), Inches(0.65), Inches(0.65),
             ACC)
        txt(slide, num, sx + Inches(0.15), Inches(1.25), Inches(0.65), Inches(0.65),
            sz=22, bold=True, clr=RGBColor(0xFF, 0xFF, 0xFF), align=PP_ALIGN.CENTER)
        txt(slide, title, sx + Inches(0.9), Inches(1.3), cw - Inches(1.05), Inches(0.5),
            sz=17, bold=True, clr=PRI)
        txt(slide, body, sx + Inches(0.15), Inches(2.0), cw - Inches(0.3), Inches(2.4),
            sz=13, clr=TXT)
        # Connector arrow (not last)
        if i < 3:
            txt(slide, "→", sx + cw + Inches(0.05), Inches(2.5), Inches(0.3), Inches(0.5),
                sz=22, bold=True, clr=ACC, align=PP_ALIGN.CENTER)

    rect(slide, Inches(0.6), Inches(5.0), Inches(12.13), Inches(0.85),
         RGBColor(0xEE, 0xF2, 0xFF), ACC, Pt(1))
    txt(slide, '"Minutes, not days. Every verdict traceable to a document and page."',
        Inches(0.8), Inches(5.12), Inches(11.9), Inches(0.65),
        sz=15, bold=True, clr=ACC, align=PP_ALIGN.CENTER)


# ── Slide 4 ─────────────────────────────────────────────────────────────────
def s4(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "System Architecture")

    bw, bh = Inches(2.5), Inches(0.52)

    def abox(x, y, label, clr=RGBColor(0xF1, 0xF5, 0xF9)):
        rect(slide, x, y, bw, bh, clr, GRD, Pt(1))
        txt(slide, label, x + Inches(0.1), y + Inches(0.06),
            bw - Inches(0.2), bh - Inches(0.1), sz=12, clr=TXT, align=PP_ALIGN.CENTER)

    def arr(x, y):
        rect(slide, x + Inches(1.15), y, Inches(0.2), Inches(0.28), ACC)

    lx = Inches(0.6)
    abox(lx, Inches(1.0), "Tender PDF")
    arr(lx, Inches(1.52))
    abox(lx, Inches(1.8), "DeepSeek LLM\n(Extract Criteria)")
    arr(lx, Inches(2.32))
    abox(lx, Inches(2.6), "Criteria JSON\n(C1–C5 structured)")

    rx = Inches(4.0)
    abox(rx, Inches(1.0), "Bidder Docs\n(PDFs · scans · photos)")
    arr(rx, Inches(1.52))
    abox(rx, Inches(1.8), "3-Tier OCR\n① PyMuPDF ② Tesseract ③ Vision LLM")
    arr(rx, Inches(2.32))
    abox(rx, Inches(2.6), "Vector Index\n(all-MiniLM-L6-v2)")

    cx = Inches(3.15)
    arr(cx, Inches(3.12))
    abox(Inches(2.1), Inches(3.4), "DeepSeek LLM — Evaluate each criterion",
         RGBColor(0xEE, 0xF2, 0xFF))

    rect(slide, Inches(0.9), Inches(4.15), Inches(2.0), Inches(0.52),
         RGBColor(0xDC, 0xFC, 0xE7), GRN, Pt(1))
    txt(slide, "eligible / not_eligible", Inches(0.9), Inches(4.15), Inches(2.0), Inches(0.52),
        sz=11, clr=GRN, align=PP_ALIGN.CENTER)

    rect(slide, Inches(3.5), Inches(4.15), Inches(2.2), Inches(0.52),
         RGBColor(0xFE, 0xF3, 0xC7), AMB, Pt(1))
    txt(slide, "needs_review\nHuman Review Queue", Inches(3.5), Inches(4.15), Inches(2.2), Inches(0.52),
        sz=11, clr=AMB, align=PP_ALIGN.CENTER)

    abox(Inches(2.1), Inches(5.0), "SQLite Audit Log")

    rect(slide, Inches(7.2), Inches(1.0), Inches(5.7), Inches(5.0),
         RGBColor(0xF8, 0xF9, 0xFF), ACC, Pt(1))
    txt(slide, "Key Technical Facts", Inches(7.35), Inches(1.1), Inches(5.4), Inches(0.4),
        sz=14, bold=True, clr=ACC)
    facts = [
        "Single-process Streamlit app — no separate backend",
        "Deployable to Streamlit Cloud or HuggingFace Spaces",
        "All storage is local: SQLite + in-memory vector index",
        "Only external dependency: DeepSeek API",
    ]
    for i, f in enumerate(facts):
        txt(slide, f"• {f}", Inches(7.35), Inches(1.65) + Inches(0.65 * i),
            Inches(5.4), Inches(0.55), sz=13, clr=TXT)


# ── Slide 5 ─────────────────────────────────────────────────────────────────
def s5(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "Three-Tier OCR — Handling Any Document Format")
    mpl_style()

    # OCR confidence bar chart
    fig, ax = plt.subplots(figsize=(4.8, 3.2))
    tiers = ["Tier 1\nPyMuPDF", "Tier 2\nTesseract", "Tier 3\nVision LLM"]
    vals = [100, 60, 95]
    colors_ = [HEX["blu"], HEX["pur"], HEX["amb"]]
    bars = ax.bar(tiers, vals, color=colors_, width=0.5, zorder=3)
    ax.set_ylabel("Confidence (%)", color=HEX["txt2"], fontsize=10)
    ax.set_ylim(0, 110)
    ax.set_title("OCR confidence by tier", color=HEX["pri"], fontsize=11, pad=6)
    for bar, val in zip(bars, vals):
        ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 1,
                f"{val}%", ha="center", va="bottom", fontsize=11,
                fontweight="bold", color=HEX["pri"])
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    png_to_slide(slide, fig, Inches(0.6), Inches(1.0), Inches(5.0), Inches(3.8))

    tiers_info = [
        ("Tier 1 — PyMuPDF", "Trigger: Typed / digital PDF\nCost: Free, instant\nConf: 1.0 (lossless)\nLabel: Typed PDF",
         RGBColor(0x3B, 0x82, 0xF6)),
        ("Tier 2 — Tesseract", "Trigger: Scanned PDF / image\nCost: Free, local\nConf: Mean per-word scores\nLabel: Tesseract",
         RGBColor(0x8B, 0x5C, 0xF6)),
        ("Tier 3 — Vision LLM", "Trigger: Tesseract conf < 65%\nCost: One API call\nConf: 0.95\nLabel: Vision LLM",
         AMB),
    ]
    cw = Inches(2.55)
    for i, (title, body, accent) in enumerate(tiers_info):
        sx = Inches(6.1) + i * Inches(2.35)
        rect(slide, sx, Inches(1.0), cw, Inches(3.5), RGBColor(0xF8, 0xF9, 0xFF), accent, Pt(2))
        rect(slide, sx, Inches(1.0), cw, Inches(0.08), accent)
        txt(slide, title, sx + Inches(0.12), Inches(1.12), cw - Inches(0.24), Inches(0.45),
            sz=13, bold=True, clr=accent)
        txt(slide, body, sx + Inches(0.12), Inches(1.62), cw - Inches(0.24), Inches(2.5),
            sz=12, clr=TXT)

    rect(slide, Inches(0.6), Inches(5.0), Inches(12.13), Inches(1.75),
         RGBColor(0xEE, 0xF2, 0xFF), ACC, Pt(1))
    txt(slide, "Demo Scenario",
        Inches(0.8), Inches(5.1), Inches(8), Inches(0.35),
        sz=13, bold=True, clr=ACC)
    demo = ("Bidder C submits a blurry, rotated CA certificate scan. "
            "Tesseract reads it at ~55% confidence. Vision LLM transcribes the turnover figure correctly. "
            "Combined confidence = 0.58 → routed to human review. "
            "Borderline evidence requires a human — this is intentional.")
    txt(slide, demo, Inches(0.8), Inches(5.52), Inches(12.0), Inches(1.1), sz=13, clr=TXT)


# ── Slide 6 ─────────────────────────────────────────────────────────────────
def s6(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "Every Decision is Explainable and Auditable")

    lx = Inches(0.6)
    rect(slide, lx, Inches(1.1), Inches(5.85), Inches(4.0),
         RGBColor(0xF8, 0xF9, 0xFF), ACC, Pt(1))
    rect(slide, lx, Inches(1.1), Inches(0.06), Inches(4.0), ACC)
    txt(slide, "Criterion-Level Verdicts", lx + Inches(0.2), Inches(1.2),
        Inches(5.5), Inches(0.42), sz=15, bold=True, clr=ACC)
    left_lines = [
        "Each (bidder × criterion) pair shows:",
        "• Which criterion was checked",
        "• Which document and page provided evidence",
        "• What value was extracted (e.g. 'INR 6.2 Cr')",
        "• Which OCR tier read the document",
        "• Combined confidence score (0–100%)",
        "• Plain-English reason",
    ]
    for i, line in enumerate(left_lines):
        c2 = TXT2 if i == 0 else TXT
        txt(slide, line, lx + Inches(0.2), Inches(1.68) + Inches(0.42 * i),
            Inches(5.5), Inches(0.38), sz=13, clr=c2)

    rx = Inches(6.98)
    rect(slide, rx, Inches(1.1), Inches(5.85), Inches(4.0),
         RGBColor(0xF8, 0xF9, 0xFF), ACC, Pt(1))
    rect(slide, rx, Inches(1.1), Inches(0.06), Inches(4.0), ACC)
    txt(slide, "Audit Trail", rx + Inches(0.2), Inches(1.2),
        Inches(5.5), Inches(0.42), sz=15, bold=True, clr=ACC)
    right_lines = [
        "Every action logged with:",
        "• UTC timestamp",
        "• Action type: criteria_extracted / bidder_processed",
        "  criterion_evaluated / human_review_action",
        "  vision_ocr_invoked / precomputed_fallback_used",
        "• Model version & Actor (system / officer)",
        "• Full payload JSON — Exportable as CSV",
    ]
    for i, line in enumerate(right_lines):
        c2 = TXT2 if i == 0 else TXT
        txt(slide, line, rx + Inches(0.2), Inches(1.68) + Inches(0.42 * i),
            Inches(5.5), Inches(0.38), sz=13, clr=c2)

    rect(slide, Inches(0.6), Inches(5.38), Inches(12.13), Inches(1.22),
         RGBColor(0xFE, 0xF3, 0xC7), AMB, Pt(2))
    txt(slide, "The Safety Rule:",
        Inches(0.8), Inches(5.45), Inches(5), Inches(0.38),
        sz=15, bold=True, clr=AMB)
    txt(slide, ("If combined confidence is 0.55–0.80 AND verdict is not_eligible, "
                "the verdict is automatically downgraded to needs_review. "
                "A bidder is NEVER silently disqualified at medium confidence."),
        Inches(0.8), Inches(5.88), Inches(12), Inches(0.65),
        sz=13, clr=TXT)


# ── Slide 7 ─────────────────────────────────────────────────────────────────
def s7(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "Demo: Three Bidders, Three Outcomes")
    mpl_style()

    # Verdicts matrix: 3 bidders × 5 criteria
    criteria = ["C1\nTurnover", "C2\nProjects", "C3\nGST", "C4\nISO", "C5\nExperience"]
    bidders = ["Bidder A\n(Apex)", "Bidder B\n(BuildRight)", "Bidder C\n(Shree)"]
    verdicts = [
        ["E", "E", "E", "E", "E"],
        ["N", "E", "E", "E", "E"],
        ["R", "R", "E", "E", "E"],
    ]
    color_map = {"E": HEX["grn"], "N": HEX["red"], "R": HEX["amb"]}
    label_map = {"E": "E", "N": "N", "R": "R"}

    fig, ax = plt.subplots(figsize=(5.2, 3.2))
    for r, row in enumerate(verdicts):
        for col, v in enumerate(row):
            c_ = color_map[v]
            ax.add_patch(mpatches.FancyBboxPatch(
                (col + 0.05, r + 0.05), 0.9, 0.9,
                boxstyle="round,pad=0.05", facecolor=c_, edgecolor="white", lw=2))
            ax.text(col + 0.5, r + 0.5, label_map[v],
                    ha="center", va="center", fontsize=16,
                    fontweight="bold", color="white")
    ax.set_xlim(0, 5)
    ax.set_ylim(0, 3)
    ax.set_xticks([i + 0.5 for i in range(5)])
    ax.set_xticklabels(criteria, fontsize=9)
    ax.set_yticks([i + 0.5 for i in range(3)])
    ax.set_yticklabels(bidders, fontsize=9)
    ax.set_title("Verdict Matrix (E=Eligible, N=Not Eligible, R=Review)",
                 color=HEX["pri"], fontsize=10, pad=6)
    ax.grid(False)
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    ax.spines["bottom"].set_visible(False)
    ax.spines["left"].set_visible(False)
    png_to_slide(slide, fig, Inches(0.6), Inches(1.0), Inches(5.8), Inches(4.0))

    bidders_info = [
        ("Bidder A — Apex Constructions", GRN, "ELIGIBLE",
         ["C1 INR 6.37 Cr avg — PASS",
          "C2 5 completed projects — PASS",
          "C3 GST active — PASS",
          "C4 ISO 9001:2015 valid — PASS",
          "Confidence ≥ 93% all criteria"]),
        ("Bidder B — BuildRight Enterprises", RED_C, "NOT ELIGIBLE",
         ["C1 INR 1.5 Cr avg — FAIL",
          "Below required INR 5 Cr",
          "C2–C4: All pass",
          "Disqualified, high conf (95%)"]),
        ("Bidder C — Shree Constructions", AMB, "NEEDS REVIEW",
         ["C1 Blurry scan: Vision LLM",
          "INR 5.4 Cr, conf 0.58 → review",
          "C2: 3 projects (borderline)",
          "C3–C4: Pass"]),
    ]
    cw = Inches(2.2)
    for i, (name, color, verdict, bullets) in enumerate(bidders_info):
        sx = Inches(6.9) + i * Inches(2.15)
        rect(slide, sx, Inches(1.0), cw, Inches(4.0),
             RGBColor(0xF8, 0xF9, 0xFF), color, Pt(2))
        rect(slide, sx, Inches(1.0), cw, Inches(0.08), color)
        txt(slide, name, sx + Inches(0.1), Inches(1.1), cw - Inches(0.2), Inches(0.45),
            sz=11, bold=True, clr=PRI)
        rect(slide, sx + Inches(0.1), Inches(1.62), cw - Inches(0.2), Inches(0.32), color)
        txt(slide, verdict, sx + Inches(0.1), Inches(1.62), cw - Inches(0.2), Inches(0.32),
            sz=11, bold=True, clr=RGBColor(0xFF, 0xFF, 0xFF), align=PP_ALIGN.CENTER)
        for j, b in enumerate(bullets):
            txt(slide, b, sx + Inches(0.1), Inches(2.05) + Inches(0.38 * j),
                cw - Inches(0.2), Inches(0.34), sz=11, clr=TXT)

    # Metric strip
    metrics = [
        ("Criteria extracted", "5"),
        ("Bidder docs processed", "15"),
        ("LLM evaluation calls", "15"),
        ("Vision OCR invocations", "1"),
        ("Human review items", "1"),
        ("Total audit entries", "20+"),
    ]
    rect(slide, Inches(0.6), Inches(5.2), Inches(12.13), Inches(0.9),
         RGBColor(0xEE, 0xF2, 0xFF), ACC, Pt(1))
    mw = Inches(2.0)
    for i, (lbl, val) in enumerate(metrics):
        mx = Inches(0.7) + i * Inches(2.0)
        txt(slide, val, mx, Inches(5.27), mw, Inches(0.38),
            sz=20, bold=True, clr=ACC, align=PP_ALIGN.CENTER)
        txt(slide, lbl, mx, Inches(5.7), mw, Inches(0.32),
            sz=11, clr=TXT2, align=PP_ALIGN.CENTER)


# ── Slide 8 ─────────────────────────────────────────────────────────────────
def s8(prs):
    slide = blank(prs)
    bg(slide)
    heading(slide, "Stack, Impact & What's Next")
    stack = [
        ("UI & orchestration", "Streamlit 1.39"),
        ("LLM", "DeepSeek API (OpenAI-compatible)"),
        ("OCR Tier 1", "PyMuPDF 1.24"),
        ("OCR Tier 2", "Tesseract"),
        ("OCR Tier 3", "DeepSeek Vision LLM"),
        ("Semantic retrieval", "sentence-transformers all-MiniLM-L6-v2"),
        ("Data validation", "Pydantic v2"),
        ("Audit log", "SQLite"),
        ("Deployment", "Streamlit Cloud / HuggingFace Spaces"),
    ]
    rect(slide, Inches(0.6), Inches(1.05), Inches(6.1), Inches(0.4),
         RGBColor(0xEE, 0xF2, 0xFF), ACC, Pt(1))
    txt(slide, "Component", Inches(0.7), Inches(1.1), Inches(2.7), Inches(0.3),
        sz=13, bold=True, clr=ACC)
    txt(slide, "Technology", Inches(3.55), Inches(1.1), Inches(2.9), Inches(0.3),
        sz=13, bold=True, clr=ACC)
    for i, (comp, tech) in enumerate(stack):
        ry = Inches(1.45) + Inches(0.38 * i)
        bg_r = RGBColor(0xF8, 0xF9, 0xFF) if i % 2 == 0 else BG
        rect(slide, Inches(0.6), ry, Inches(6.1), Inches(0.38), bg_r)
        txt(slide, comp, Inches(0.7), ry + Inches(0.06), Inches(2.7), Inches(0.3),
            sz=12, clr=TXT2)
        txt(slide, tech, Inches(3.55), ry + Inches(0.06), Inches(2.9), Inches(0.3),
            sz=12, clr=TXT)

    txt(slide, "What's Next", Inches(7.3), Inches(1.05), Inches(5.6), Inches(0.42),
        sz=16, bold=True, clr=ACC)
    future = [
        "Multi-tender workspace — same bidder pool, multiple tenders",
        "GeM portal API integration — live tender ingestion",
        "Automated bidder ranking with weighted scoring",
        "LayoutLM for complex financial tables in scanned statements",
        "Multi-evaluator workflow with role-based approval",
        "Review queue email/SMS notifications",
        "Audit PDF export for procurement oversight submissions",
    ]
    for i, f in enumerate(future):
        txt(slide, f"• {f}", Inches(7.3), Inches(1.55) + Inches(0.47 * i),
            Inches(5.8), Inches(0.42), sz=13, clr=TXT)

    rect(slide, Inches(0.6), Inches(6.2), Inches(12.13), Inches(0.92),
         RGBColor(0xEE, 0xF2, 0xFF), ACC, Pt(2))
    txt(slide, ("3–5 days → minutes.  Every verdict traceable to a document, page, and model version."
                "  Built in one hackathon session. Deployable today."),
        Inches(0.8), Inches(6.3), Inches(11.9), Inches(0.75),
        sz=14, bold=True, clr=ACC, align=PP_ALIGN.CENTER)


def main():
    os.makedirs("deck", exist_ok=True)
    prs = new_prs()
    s1(prs); s2(prs); s3(prs); s4(prs)
    s5(prs); s6(prs); s7(prs); s8(prs)
    out = "deck/TenderIQ_v5_data_forward.pptx"
    prs.save(out)
    print(f"OK: Saved {out}  ({len(prs.slides)} slides)")


if __name__ == "__main__":
    main()