JKrishnanandhaa commited on
Commit
1a69cc7
·
verified ·
1 Parent(s): cc6bad6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -299,7 +299,7 @@ class ForgeryDetector:
299
  # Calculate IoU, Precision, Recall from the refined mask and probability map
300
  if num_detections > 0:
301
  # Use high-confidence areas from probability map as "predicted positive"
302
- high_conf_mask = (prob_map > 0.7).astype(np.uint8)
303
  predicted_positive = np.sum(refined_mask > 0)
304
  high_conf_positive = np.sum(high_conf_mask > 0)
305
 
@@ -412,15 +412,18 @@ class ForgeryDetector:
412
  detector = ForgeryDetector()
413
 
414
 
415
- def detect_forgery(file):
416
- """Gradio interface function"""
417
  try:
418
- if file is None:
 
 
 
419
  empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
420
  return None, None, empty_html
421
 
422
  # Get file path
423
- file_path = file if isinstance(file, str) else file
424
 
425
  # Detect forgeries
426
  overlay, metrics_gauge, results_html = detector.detect(file_path)
@@ -465,10 +468,16 @@ with gr.Blocks(css=custom_css) as demo:
465
  with gr.Row():
466
  with gr.Column(scale=1):
467
  gr.Markdown("### Upload Document")
468
- input_file = gr.Image(
469
- label="Document (Image or PDF)",
 
 
 
 
 
470
  type="filepath",
471
- sources=["upload", "webcam"]
 
472
  )
473
 
474
  with gr.Row():
@@ -555,14 +564,14 @@ with gr.Blocks(css=custom_css) as demo:
555
  # Event handlers
556
  analyze_btn.click(
557
  fn=detect_forgery,
558
- inputs=[input_file],
559
  outputs=[output_image, metrics_gauge, output_html]
560
  )
561
 
562
  clear_btn.click(
563
- fn=lambda: (None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
564
  inputs=None,
565
- outputs=[input_file, output_image, metrics_gauge, output_html]
566
  )
567
 
568
 
 
299
  # Calculate IoU, Precision, Recall from the refined mask and probability map
300
  if num_detections > 0:
301
  # Use high-confidence areas from probability map as "predicted positive"
302
+ high_conf_mask = (prob_map_resized > 0.7).astype(np.uint8)
303
  predicted_positive = np.sum(refined_mask > 0)
304
  high_conf_positive = np.sum(high_conf_mask > 0)
305
 
 
412
  detector = ForgeryDetector()
413
 
414
 
415
+ def detect_forgery(file, webcam):
416
+ """Gradio interface function - accepts file upload or webcam capture"""
417
  try:
418
+ # Prioritize file upload, fallback to webcam
419
+ input_source = file if file is not None else webcam
420
+
421
+ if input_source is None:
422
  empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
423
  return None, None, empty_html
424
 
425
  # Get file path
426
+ file_path = input_source if isinstance(input_source, str) else input_source
427
 
428
  # Detect forgeries
429
  overlay, metrics_gauge, results_html = detector.detect(file_path)
 
468
  with gr.Row():
469
  with gr.Column(scale=1):
470
  gr.Markdown("### Upload Document")
471
+ input_file = gr.File(
472
+ label="Upload Document (Image or PDF)",
473
+ file_types=["image", ".pdf"],
474
+ type="filepath"
475
+ )
476
+ input_webcam = gr.Image(
477
+ label="Or Capture from Webcam",
478
  type="filepath",
479
+ sources=["webcam"],
480
+ visible=True
481
  )
482
 
483
  with gr.Row():
 
564
  # Event handlers
565
  analyze_btn.click(
566
  fn=detect_forgery,
567
+ inputs=[input_file, input_webcam],
568
  outputs=[output_image, metrics_gauge, output_html]
569
  )
570
 
571
  clear_btn.click(
572
+ fn=lambda: (None, None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
573
  inputs=None,
574
+ outputs=[input_file, input_webcam, output_image, metrics_gauge, output_html]
575
  )
576
 
577