Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio import components
|
3 |
import numpy as np
|
4 |
import time
|
5 |
|
@@ -8,16 +7,7 @@ def placeholder_process(image):
|
|
8 |
time.sleep(1) # Simulate processing time
|
9 |
return image, "Real", 0.95
|
10 |
|
11 |
-
|
12 |
-
"""Format and display the result"""
|
13 |
-
return (
|
14 |
-
image,
|
15 |
-
f"Detection Result: {label}",
|
16 |
-
f"Confidence Score: {confidence:.2%}",
|
17 |
-
gr.update(visible=True)
|
18 |
-
)
|
19 |
-
|
20 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
21 |
# Header
|
22 |
gr.Markdown("""
|
23 |
# Face Spoofing Detection System
|
@@ -30,28 +20,26 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
30 |
with gr.Tab("Webcam Detection"):
|
31 |
with gr.Row():
|
32 |
with gr.Column(scale=2):
|
33 |
-
# Using
|
34 |
-
webcam =
|
35 |
with gr.Column(scale=1):
|
36 |
-
webcam_status =
|
37 |
-
webcam_result =
|
38 |
-
webcam_conf =
|
39 |
-
webcam_alert = components.Textbox(label="Alert", visible=False)
|
40 |
|
41 |
-
webcam_button =
|
42 |
|
43 |
# Image Upload Tab
|
44 |
with gr.Tab("Image Upload"):
|
45 |
with gr.Row():
|
46 |
with gr.Column(scale=2):
|
47 |
-
image_input =
|
48 |
with gr.Column(scale=1):
|
49 |
-
image_status =
|
50 |
-
image_result =
|
51 |
-
image_conf =
|
52 |
-
image_alert = components.Textbox(label="Alert", visible=False)
|
53 |
|
54 |
-
image_button =
|
55 |
|
56 |
# Info Section
|
57 |
with gr.Accordion("Information", open=False):
|
@@ -66,28 +54,29 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
66 |
- Position face clearly in the frame
|
67 |
- Keep steady and avoid rapid movements
|
68 |
- For best results, maintain a distance of 30-60cm from the camera
|
69 |
-
|
70 |
-
### System Requirements
|
71 |
-
- Webcam with minimum 720p resolution (for live detection)
|
72 |
-
- Stable internet connection
|
73 |
-
- Supported browsers: Chrome, Firefox, Safari
|
74 |
""")
|
75 |
|
76 |
# Event handlers
|
77 |
def update_status(is_webcam=True):
|
78 |
prefix = "Webcam" if is_webcam else "Image"
|
79 |
return f"{prefix} analysis in progress..."
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
image_button.click(
|
82 |
-
fn=
|
83 |
inputs=[image_input],
|
84 |
-
outputs=[image_status,
|
85 |
)
|
86 |
|
87 |
webcam_button.click(
|
88 |
-
fn=
|
89 |
inputs=[webcam],
|
90 |
-
outputs=[webcam_status,
|
91 |
)
|
92 |
|
93 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import numpy as np
|
3 |
import time
|
4 |
|
|
|
7 |
time.sleep(1) # Simulate processing time
|
8 |
return image, "Real", 0.95
|
9 |
|
10 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Header
|
12 |
gr.Markdown("""
|
13 |
# Face Spoofing Detection System
|
|
|
20 |
with gr.Tab("Webcam Detection"):
|
21 |
with gr.Row():
|
22 |
with gr.Column(scale=2):
|
23 |
+
# Using basic Image component with webcam
|
24 |
+
webcam = gr.Image(shape=(480, 640), label="Webcam Feed")
|
25 |
with gr.Column(scale=1):
|
26 |
+
webcam_status = gr.Textbox(label="Status", value="Ready", interactive=False)
|
27 |
+
webcam_result = gr.Textbox(label="Detection", interactive=False)
|
28 |
+
webcam_conf = gr.Textbox(label="Confidence", interactive=False)
|
|
|
29 |
|
30 |
+
webcam_button = gr.Button("Start Detection", variant="primary")
|
31 |
|
32 |
# Image Upload Tab
|
33 |
with gr.Tab("Image Upload"):
|
34 |
with gr.Row():
|
35 |
with gr.Column(scale=2):
|
36 |
+
image_input = gr.Image(label="Upload Image")
|
37 |
with gr.Column(scale=1):
|
38 |
+
image_status = gr.Textbox(label="Status", value="Ready", interactive=False)
|
39 |
+
image_result = gr.Textbox(label="Detection", interactive=False)
|
40 |
+
image_conf = gr.Textbox(label="Confidence", interactive=False)
|
|
|
41 |
|
42 |
+
image_button = gr.Button("Analyze Image")
|
43 |
|
44 |
# Info Section
|
45 |
with gr.Accordion("Information", open=False):
|
|
|
54 |
- Position face clearly in the frame
|
55 |
- Keep steady and avoid rapid movements
|
56 |
- For best results, maintain a distance of 30-60cm from the camera
|
|
|
|
|
|
|
|
|
|
|
57 |
""")
|
58 |
|
59 |
# Event handlers
|
60 |
def update_status(is_webcam=True):
|
61 |
prefix = "Webcam" if is_webcam else "Image"
|
62 |
return f"{prefix} analysis in progress..."
|
63 |
+
|
64 |
+
def process_image(img):
|
65 |
+
if img is None:
|
66 |
+
return "No image provided", "", ""
|
67 |
+
result, label, conf = placeholder_process(img)
|
68 |
+
return update_status(False), f"Detection: {label}", f"Confidence: {conf:.2%}"
|
69 |
|
70 |
image_button.click(
|
71 |
+
fn=process_image,
|
72 |
inputs=[image_input],
|
73 |
+
outputs=[image_status, image_result, image_conf]
|
74 |
)
|
75 |
|
76 |
webcam_button.click(
|
77 |
+
fn=process_image,
|
78 |
inputs=[webcam],
|
79 |
+
outputs=[webcam_status, webcam_result, webcam_conf]
|
80 |
)
|
81 |
|
82 |
# Launch the interface
|