Seth0330 commited on
Commit
ace9734
·
verified ·
1 Parent(s): 1c49f02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -35
app.py CHANGED
@@ -27,20 +27,6 @@ st.markdown("""
27
  padding: 10px 32px !important; font-weight: 700; border: none !important; font-size: 18px !important;
28
  margin-top: 12px !important;
29
  }
30
- .styled-table th {
31
- background: #f3ecff !important;
32
- color: #42318d !important;
33
- font-weight: bold !important;
34
- font-size: 16px !important;
35
- padding: 10px 6px !important;
36
- border-bottom: 2px solid #A020F0 !important;
37
- }
38
- .styled-table td {
39
- font-size: 15px !important;
40
- padding: 8px 4px !important;
41
- word-break: break-word;
42
- max-width: 220px;
43
- }
44
  </style>
45
  """, unsafe_allow_html=True)
46
 
@@ -295,13 +281,57 @@ def fuzzy_match_type(detected_type, checklist_types):
295
  best_score = score
296
  return best_type, best_score
297
 
298
- def color_row(row):
299
- if row["Accepted"] == "Yes":
300
- return ['background-color: #e7ffe7'] * len(row)
301
- elif row["Accepted"] == "No":
302
- return ['background-color: #fff1f0'] * len(row)
303
- else:
304
- return [''] * len(row)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
  # ========== PROCESSING ==========
307
  if 'run_btn' not in locals():
@@ -402,22 +432,11 @@ if run_btn and uploaded_files:
402
  debug_data.append({uploaded_file.name: debug})
403
  status_box.success("Validation complete. See result below.")
404
 
405
- # ==== Results table with custom styling ====
406
  if results:
407
  st.success("All validations complete.")
408
- df = pd.DataFrame(results)
409
- def style_row(row):
410
- color = "#e7ffe7" if row["Accepted"] == "Yes" else "#fff1f0"
411
- return [f"background-color: {color}"]*len(row)
412
- styled_df = df.style.apply(style_row, axis=1)\
413
- .set_table_attributes('class="styled-table"')\
414
- .set_properties(**{
415
- 'font-size': '15px',
416
- 'word-break': 'break-word',
417
- 'border': '1px solid #ddd'
418
- })
419
- st.markdown('<h4 style="margin-top:28px;">Validation Results</h4>', unsafe_allow_html=True)
420
- st.write(styled_df.to_html(escape=False), unsafe_allow_html=True)
421
  else:
422
  st.warning("No valid results.")
423
 
 
27
  padding: 10px 32px !important; font-weight: 700; border: none !important; font-size: 18px !important;
28
  margin-top: 12px !important;
29
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  </style>
31
  """, unsafe_allow_html=True)
32
 
 
281
  best_score = score
282
  return best_type, best_score
283
 
284
+ # ========== CARD RENDERING FUNCTION ==========
285
+
286
+ def show_validation_card(result):
287
+ accepted = result["Accepted"] == "Yes"
288
+ expired = result["Expired"] == "Yes"
289
+ genuine = result["Genuine"] == "Yes"
290
+
291
+ decision_color = "#d32f2f" if not accepted else "#388e3c"
292
+ yes_color = "#388e3c"
293
+ no_color = "#d32f2f"
294
+ bg_reason = "#ffeaea" if not accepted else "#eafbe8"
295
+
296
+ st.markdown(f"""
297
+ <div style="border-radius:16px;border:2px solid #A020F0; margin-bottom:32px; background:#f9f7ff;padding:18px 22px 22px 22px;box-shadow:0 3px 16px #0001;">
298
+ <div style="font-size:18px;font-weight:bold;letter-spacing:1px;margin-bottom:6px;">{result['File']}</div>
299
+ <table style="width:100%;border:none;margin-bottom:12px;">
300
+ <tr>
301
+ <td style="width:40%;font-size:17px;font-weight:700;">Decision:</td>
302
+ <td style="width:60%;font-size:17px;font-weight:700;color:{decision_color};">{'Accepted' if accepted else 'Rejected'}</td>
303
+ </tr>
304
+ <tr>
305
+ <td style="font-size:17px;font-weight:700;">Confidence:</td>
306
+ <td style="font-size:17px;">{result['Confidence']}%</td>
307
+ </tr>
308
+ </table>
309
+ <div style="border-radius:8px;background:{bg_reason};padding:11px 14px 11px 14px;color:#720000;font-size:15.5px;margin-bottom:17px;">
310
+ <span style="font-weight:bold;">Reason:</span><br>{result['Reason']}
311
+ </div>
312
+ <table style="width:100%;margin-top:10px;margin-bottom:5px;">
313
+ <tr>
314
+ <td style="font-weight:600;font-size:15px;border-bottom:1px solid #ddd;padding-bottom:3px;">Detected Document:</td>
315
+ <td style="font-weight:600;font-size:15px;border-bottom:1px solid #ddd;padding-bottom:3px;">Matched with Checklist:</td>
316
+ </tr>
317
+ <tr>
318
+ <td style="color:{yes_color if accepted else '#222'};font-weight:600;font-size:15px;">{result['Detected Type']}</td>
319
+ <td style="color:{yes_color if accepted else '#222'};font-weight:600;font-size:15px;">{result['Checklist Match']}</td>
320
+ </tr>
321
+ <tr>
322
+ <td style="font-weight:600;font-size:15px;border-bottom:1px solid #ddd;padding-bottom:3px;">Genuine:</td>
323
+ <td style="font-weight:600;font-size:15px;border-bottom:1px solid #ddd;padding-bottom:3px;">Expired:</td>
324
+ </tr>
325
+ <tr>
326
+ <td style="color:{yes_color if genuine else no_color};font-weight:600;font-size:15px;">{"Yes" if genuine else "No"}</td>
327
+ <td style="color:{yes_color if not expired else no_color};font-weight:600;font-size:15px;">{"Yes" if expired else "No"}</td>
328
+ </tr>
329
+ </table>
330
+ <div style="color:#555;font-size:14px;margin-top:7px;">
331
+ <b>Expiry Date:</b> {result["Expiry Date"]}
332
+ </div>
333
+ </div>
334
+ """, unsafe_allow_html=True)
335
 
336
  # ========== PROCESSING ==========
337
  if 'run_btn' not in locals():
 
432
  debug_data.append({uploaded_file.name: debug})
433
  status_box.success("Validation complete. See result below.")
434
 
435
+ # ==== Card-style results ====
436
  if results:
437
  st.success("All validations complete.")
438
+ for result in results:
439
+ show_validation_card(result)
 
 
 
 
 
 
 
 
 
 
 
440
  else:
441
  st.warning("No valid results.")
442