Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -412,14 +412,14 @@ class ForgeryDetector:
|
|
| 412 |
detector = ForgeryDetector()
|
| 413 |
|
| 414 |
|
| 415 |
-
def detect_forgery(
|
| 416 |
-
"""Gradio interface function - handles
|
| 417 |
try:
|
| 418 |
-
# Prioritize
|
| 419 |
-
if
|
| 420 |
-
file_path =
|
| 421 |
-
elif
|
| 422 |
-
file_path =
|
| 423 |
else:
|
| 424 |
empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
|
| 425 |
return None, None, empty_html
|
|
@@ -451,16 +451,6 @@ custom_css = """
|
|
| 451 |
background-color: #6A89A7 !important;
|
| 452 |
color: white !important;
|
| 453 |
}
|
| 454 |
-
.upload-container {
|
| 455 |
-
border: 1px solid #444 !important;
|
| 456 |
-
border-radius: 10px !important;
|
| 457 |
-
padding: 10px !important;
|
| 458 |
-
}
|
| 459 |
-
.pdf-btn {
|
| 460 |
-
background-color: #d9534f !important;
|
| 461 |
-
color: white !important;
|
| 462 |
-
font-size: 0.9em !important;
|
| 463 |
-
}
|
| 464 |
"""
|
| 465 |
|
| 466 |
# Create Gradio interface
|
|
@@ -477,20 +467,25 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 477 |
with gr.Row():
|
| 478 |
with gr.Column(scale=1):
|
| 479 |
gr.Markdown("### Upload Document")
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
with gr.Row():
|
| 496 |
clear_btn = gr.Button("🧹 Clear", elem_classes="clear-btn")
|
|
@@ -574,16 +569,23 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 574 |
)
|
| 575 |
|
| 576 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
analyze_btn.click(
|
| 578 |
fn=detect_forgery,
|
| 579 |
-
inputs=[
|
| 580 |
outputs=[output_image, metrics_gauge, output_html]
|
| 581 |
)
|
| 582 |
|
| 583 |
clear_btn.click(
|
| 584 |
-
fn=lambda: (None, None, None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
|
| 585 |
inputs=None,
|
| 586 |
-
outputs=[
|
| 587 |
)
|
| 588 |
|
| 589 |
|
|
|
|
| 412 |
detector = ForgeryDetector()
|
| 413 |
|
| 414 |
|
| 415 |
+
def detect_forgery(file_input, webcam_input):
|
| 416 |
+
"""Gradio interface function - handles unified file upload and webcam"""
|
| 417 |
try:
|
| 418 |
+
# Prioritize file upload, fallback to webcam
|
| 419 |
+
if file_input is not None:
|
| 420 |
+
file_path = file_input
|
| 421 |
+
elif webcam_input is not None:
|
| 422 |
+
file_path = webcam_input
|
| 423 |
else:
|
| 424 |
empty_html = "<div style='padding:12px; border:1px solid #d9534f; border-radius:8px;'>❌ <b>No file uploaded.</b></div>"
|
| 425 |
return None, None, empty_html
|
|
|
|
| 451 |
background-color: #6A89A7 !important;
|
| 452 |
color: white !important;
|
| 453 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
"""
|
| 455 |
|
| 456 |
# Create Gradio interface
|
|
|
|
| 467 |
with gr.Row():
|
| 468 |
with gr.Column(scale=1):
|
| 469 |
gr.Markdown("### Upload Document")
|
| 470 |
+
|
| 471 |
+
# Single unified input that accepts images and PDFs
|
| 472 |
+
input_file = gr.File(
|
| 473 |
+
label="📤 Upload Image/PDF or 📷 Use Webcam",
|
| 474 |
+
file_types=["image", ".pdf"],
|
| 475 |
+
type="filepath"
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
# Hidden webcam component for capture functionality
|
| 479 |
+
input_webcam = gr.Image(
|
| 480 |
+
label="Webcam Capture",
|
| 481 |
+
type="filepath",
|
| 482 |
+
sources=["webcam"],
|
| 483 |
+
visible=False
|
| 484 |
+
)
|
| 485 |
+
|
| 486 |
+
# Button to trigger webcam
|
| 487 |
+
with gr.Row():
|
| 488 |
+
webcam_btn = gr.Button("📷 Open Webcam", size="sm")
|
| 489 |
|
| 490 |
with gr.Row():
|
| 491 |
clear_btn = gr.Button("🧹 Clear", elem_classes="clear-btn")
|
|
|
|
| 569 |
)
|
| 570 |
|
| 571 |
# Event handlers
|
| 572 |
+
# Toggle webcam visibility
|
| 573 |
+
webcam_btn.click(
|
| 574 |
+
fn=lambda: gr.update(visible=True),
|
| 575 |
+
inputs=None,
|
| 576 |
+
outputs=[input_webcam]
|
| 577 |
+
)
|
| 578 |
+
|
| 579 |
analyze_btn.click(
|
| 580 |
fn=detect_forgery,
|
| 581 |
+
inputs=[input_file, input_webcam],
|
| 582 |
outputs=[output_image, metrics_gauge, output_html]
|
| 583 |
)
|
| 584 |
|
| 585 |
clear_btn.click(
|
| 586 |
+
fn=lambda: (None, None, gr.update(visible=False), None, None, "<i>No analysis yet. Upload a document and click Analyze.</i>"),
|
| 587 |
inputs=None,
|
| 588 |
+
outputs=[input_file, input_webcam, input_webcam, output_image, metrics_gauge, output_html]
|
| 589 |
)
|
| 590 |
|
| 591 |
|