Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -412,15 +412,18 @@ class ForgeryDetector:
|
|
| 412 |
detector = ForgeryDetector()
|
| 413 |
|
| 414 |
|
| 415 |
-
def detect_forgery(file):
|
| 416 |
-
"""Gradio interface function - handles
|
| 417 |
try:
|
| 418 |
-
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
| 420 |
return None, None, empty_html
|
| 421 |
|
| 422 |
# Detect forgeries
|
| 423 |
-
overlay, metrics_gauge, results_html = detector.detect(
|
| 424 |
|
| 425 |
return overlay, metrics_gauge, results_html
|
| 426 |
|
|
@@ -463,11 +466,20 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 463 |
with gr.Column(scale=1):
|
| 464 |
gr.Markdown("### Upload Document")
|
| 465 |
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
|
| 472 |
with gr.Row():
|
| 473 |
clear_btn = gr.Button("🧹 Clear", elem_classes="clear-btn")
|
|
@@ -553,14 +565,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 553 |
# Event handlers
|
| 554 |
analyze_btn.click(
|
| 555 |
fn=detect_forgery,
|
| 556 |
-
inputs=[input_file],
|
| 557 |
outputs=[output_image, metrics_gauge, output_html]
|
| 558 |
)
|
| 559 |
|
| 560 |
clear_btn.click(
|
| 561 |
-
fn=lambda: (None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
|
| 562 |
inputs=None,
|
| 563 |
-
outputs=[input_file, output_image, metrics_gauge, output_html]
|
| 564 |
)
|
| 565 |
|
| 566 |
|
|
|
|
| 412 |
detector = ForgeryDetector()
|
| 413 |
|
| 414 |
|
| 415 |
+
def detect_forgery(file, webcam):
|
| 416 |
+
"""Gradio interface function - handles file uploads and webcam capture"""
|
| 417 |
try:
|
| 418 |
+
# Use whichever input has data
|
| 419 |
+
source = file if file is not None else webcam
|
| 420 |
+
|
| 421 |
+
if source is None:
|
| 422 |
+
empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No input provided.</b> Please upload a file or use webcam.</div>"
|
| 423 |
return None, None, empty_html
|
| 424 |
|
| 425 |
# Detect forgeries
|
| 426 |
+
overlay, metrics_gauge, results_html = detector.detect(source)
|
| 427 |
|
| 428 |
return overlay, metrics_gauge, results_html
|
| 429 |
|
|
|
|
| 466 |
with gr.Column(scale=1):
|
| 467 |
gr.Markdown("### Upload Document")
|
| 468 |
|
| 469 |
+
with gr.Tabs():
|
| 470 |
+
with gr.Tab("📤 Upload File"):
|
| 471 |
+
input_file = gr.File(
|
| 472 |
+
label="Upload Image or PDF",
|
| 473 |
+
file_types=["image", ".pdf"],
|
| 474 |
+
type="filepath"
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
with gr.Tab("📷 Webcam"):
|
| 478 |
+
input_webcam = gr.Image(
|
| 479 |
+
label="Capture from Webcam",
|
| 480 |
+
type="filepath",
|
| 481 |
+
sources=["webcam"]
|
| 482 |
+
)
|
| 483 |
|
| 484 |
with gr.Row():
|
| 485 |
clear_btn = gr.Button("🧹 Clear", elem_classes="clear-btn")
|
|
|
|
| 565 |
# Event handlers
|
| 566 |
analyze_btn.click(
|
| 567 |
fn=detect_forgery,
|
| 568 |
+
inputs=[input_file, input_webcam],
|
| 569 |
outputs=[output_image, metrics_gauge, output_html]
|
| 570 |
)
|
| 571 |
|
| 572 |
clear_btn.click(
|
| 573 |
+
fn=lambda: (None, None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
|
| 574 |
inputs=None,
|
| 575 |
+
outputs=[input_file, input_webcam, output_image, metrics_gauge, output_html]
|
| 576 |
)
|
| 577 |
|
| 578 |
|