ngupta2026 commited on
Commit
d14dfaa
Β·
verified Β·
1 Parent(s): 5f40dd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -19
app.py CHANGED
@@ -1,7 +1,7 @@
1
  # =====================================================
2
  # AI INSURANCE CLAIM GENERATOR
3
  # FINAL VERSION
4
- # Working Extraction Logic + Professional PDF + Email
5
  # Hugging Face Space Ready
6
  # =====================================================
7
 
@@ -14,12 +14,14 @@ import requests
14
  import os
15
  import io
16
  import base64
 
17
 
18
  from transformers import LayoutLMTokenizerFast, LayoutLMForTokenClassification
19
 
20
  # PDF LIBRARY
21
  from reportlab.lib.pagesizes import A4
22
  from reportlab.pdfgen import canvas
 
23
 
24
  # =====================================================
25
  # CONFIG
@@ -127,7 +129,7 @@ def extract_total(words):
127
  return "Not Found"
128
 
129
  # =====================================================
130
- # PROFESSIONAL PDF GENERATOR
131
  # =====================================================
132
  def create_pdf_base64(extracted):
133
 
@@ -136,28 +138,70 @@ def create_pdf_base64(extracted):
136
  p = canvas.Canvas(buffer, pagesize=A4)
137
  width, height = A4
138
 
139
- y = height - 60
 
 
 
 
140
 
141
- p.setFont("Helvetica-Bold", 18)
142
- p.drawString(50, y, "AI Insurance Claim Report")
 
143
 
144
- y -= 40
145
- p.setFont("Helvetica", 12)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  rows = [
148
- f"Provider Name : {extracted['company']}",
149
- f"Bill Date : {extracted['date']}",
150
- f"Claim Amount : {extracted['total']}",
151
- f"Confidence : {extracted['confidence']}",
152
- f"Decision : {extracted['decision']}"
 
153
  ]
154
 
155
- for row in rows:
156
- p.drawString(50, y, row)
157
- y -= 28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- y -= 20
160
- p.drawString(50, y, "Generated by AI Insurance Claim Generator")
 
 
 
161
 
162
  p.showPage()
163
  p.save()
@@ -296,7 +340,7 @@ def send_claim_email(to_email, extracted):
296
  <p><b>Date:</b> {extracted['date']}</p>
297
  <p><b>Amount:</b> β‚Ή{extracted['total']}</p>
298
 
299
- <p>Attached: AI Claim Report PDF</p>
300
  """
301
 
302
  try:
@@ -372,7 +416,7 @@ demo = gr.Interface(
372
  ],
373
 
374
  title="πŸ“„ AI Insurance Claim Generator",
375
- description="Upload receipt β†’ Extract fields β†’ Generate PDF β†’ Auto Email"
376
  )
377
 
378
  demo.launch()
 
1
  # =====================================================
2
  # AI INSURANCE CLAIM GENERATOR
3
  # FINAL VERSION
4
+ # Accurate Extraction + Professional Claim PDF + Email
5
  # Hugging Face Space Ready
6
  # =====================================================
7
 
 
14
  import os
15
  import io
16
  import base64
17
+ from datetime import datetime
18
 
19
  from transformers import LayoutLMTokenizerFast, LayoutLMForTokenClassification
20
 
21
  # PDF LIBRARY
22
  from reportlab.lib.pagesizes import A4
23
  from reportlab.pdfgen import canvas
24
+ from reportlab.lib.colors import HexColor
25
 
26
  # =====================================================
27
  # CONFIG
 
129
  return "Not Found"
130
 
131
  # =====================================================
132
+ # PROFESSIONAL CLAIM PDF
133
  # =====================================================
134
  def create_pdf_base64(extracted):
135
 
 
138
  p = canvas.Canvas(buffer, pagesize=A4)
139
  width, height = A4
140
 
141
+ # Colors
142
+ blue = HexColor("#0B5ED7")
143
+ dark = HexColor("#222222")
144
+ gray = HexColor("#666666")
145
+ light = HexColor("#F5F7FA")
146
 
147
+ # Header Bar
148
+ p.setFillColor(blue)
149
+ p.rect(0, height - 80, width, 80, fill=1, stroke=0)
150
 
151
+ p.setFillColorRGB(1, 1, 1)
152
+ p.setFont("Helvetica-Bold", 22)
153
+ p.drawString(40, height - 50, "INSURANCE CLAIM FORM")
154
+
155
+ p.setFont("Helvetica", 10)
156
+ p.drawRightString(width - 40, height - 52, "AI Generated Report")
157
+
158
+ # Body Box
159
+ p.setFillColor(light)
160
+ p.roundRect(35, height - 430, width - 70, 290, 10, fill=1, stroke=0)
161
+
162
+ y = height - 130
163
+
164
+ p.setFillColor(dark)
165
+ p.setFont("Helvetica-Bold", 14)
166
+ p.drawString(50, y, "Claim Summary")
167
+
168
+ y -= 35
169
 
170
  rows = [
171
+ ("Claim ID", f"CLM-{datetime.now().strftime('%Y%m%d%H%M%S')}"),
172
+ ("Provider Name", extracted["company"]),
173
+ ("Bill Date", extracted["date"]),
174
+ ("Claim Amount", f"β‚Ή {extracted['total']}"),
175
+ ("Status", "Submitted"),
176
+ ("Generated On", datetime.now().strftime("%d-%m-%Y %H:%M"))
177
  ]
178
 
179
+ for label, value in rows:
180
+
181
+ p.setFillColor(gray)
182
+ p.setFont("Helvetica-Bold", 11)
183
+ p.drawString(55, y, label)
184
+
185
+ p.setFillColor(dark)
186
+ p.setFont("Helvetica", 11)
187
+ p.drawString(220, y, str(value))
188
+
189
+ y -= 32
190
+
191
+ # Footer Notes
192
+ p.setFillColor(gray)
193
+ p.setFont("Helvetica", 9)
194
+ p.drawString(
195
+ 40,
196
+ 60,
197
+ "This document was generated automatically by AI Insurance Claim Generator."
198
+ )
199
 
200
+ p.drawRightString(
201
+ width - 40,
202
+ 60,
203
+ "Confidential"
204
+ )
205
 
206
  p.showPage()
207
  p.save()
 
340
  <p><b>Date:</b> {extracted['date']}</p>
341
  <p><b>Amount:</b> β‚Ή{extracted['total']}</p>
342
 
343
+ <p>Attached: Professional Claim PDF</p>
344
  """
345
 
346
  try:
 
416
  ],
417
 
418
  title="πŸ“„ AI Insurance Claim Generator",
419
+ description="Upload receipt β†’ Extract fields β†’ Generate Claim PDF β†’ Auto Email"
420
  )
421
 
422
  demo.launch()