Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,83 +2,50 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import time
|
4 |
|
5 |
-
def
|
6 |
"""Placeholder function - replace with your backend integration"""
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
|
10 |
with gr.Blocks() as demo:
|
11 |
-
#
|
12 |
-
gr.Markdown("""
|
13 |
-
# Face Spoofing Detection System
|
14 |
-
### Detect real vs spoofed faces in real-time or from uploaded images
|
15 |
-
""")
|
16 |
|
17 |
-
# Main Interface
|
18 |
with gr.Tabs():
|
19 |
-
# Webcam Tab
|
20 |
with gr.Tab("Webcam Detection"):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
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
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
33 |
with gr.Tab("Image Upload"):
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
image_result = gr.Textbox(label="Detection", interactive=False)
|
40 |
-
image_conf = gr.Textbox(label="Confidence", interactive=False)
|
41 |
|
42 |
-
image_button
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
### How to Use
|
48 |
-
1. Choose either Webcam or Image Upload mode
|
49 |
-
2. For webcam: Click 'Start Detection' to begin real-time analysis
|
50 |
-
3. For images: Upload an image and click 'Analyze Image'
|
51 |
-
|
52 |
-
### Best Practices
|
53 |
-
- Ensure good lighting conditions
|
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 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
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
|
83 |
if __name__ == "__main__":
|
84 |
-
demo.launch(
|
|
|
2 |
import numpy as np
|
3 |
import time
|
4 |
|
5 |
+
def process_image(img):
|
6 |
"""Placeholder function - replace with your backend integration"""
|
7 |
+
if img is None:
|
8 |
+
return "No image provided", "", ""
|
9 |
+
time.sleep(1) # Simulate processing
|
10 |
+
return "Processing Complete", "Real Face", "Confidence: 95%"
|
11 |
|
12 |
with gr.Blocks() as demo:
|
13 |
+
gr.Markdown("# Face Spoofing Detection System")
|
|
|
|
|
|
|
|
|
14 |
|
|
|
15 |
with gr.Tabs():
|
|
|
16 |
with gr.Tab("Webcam Detection"):
|
17 |
+
webcam = gr.Image(label="Webcam Feed")
|
18 |
+
webcam_status = gr.Textbox(label="Status", value="Ready")
|
19 |
+
webcam_result = gr.Textbox(label="Detection Result")
|
20 |
+
webcam_conf = gr.Textbox(label="Confidence Score")
|
21 |
+
webcam_button = gr.Button("Analyze")
|
|
|
|
|
|
|
22 |
|
23 |
+
webcam_button.click(
|
24 |
+
fn=process_image,
|
25 |
+
inputs=webcam,
|
26 |
+
outputs=[webcam_status, webcam_result, webcam_conf]
|
27 |
+
)
|
28 |
+
|
29 |
with gr.Tab("Image Upload"):
|
30 |
+
image_input = gr.Image(label="Upload Image")
|
31 |
+
image_status = gr.Textbox(label="Status", value="Ready")
|
32 |
+
image_result = gr.Textbox(label="Detection Result")
|
33 |
+
image_conf = gr.Textbox(label="Confidence Score")
|
34 |
+
image_button = gr.Button("Analyze")
|
|
|
|
|
35 |
|
36 |
+
image_button.click(
|
37 |
+
fn=process_image,
|
38 |
+
inputs=image_input,
|
39 |
+
outputs=[image_status, image_result, image_conf]
|
40 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
gr.Markdown("""
|
43 |
+
### Instructions:
|
44 |
+
1. Choose either Webcam or Image Upload tab
|
45 |
+
2. For webcam: Allow camera access and take a photo
|
46 |
+
3. For images: Upload an image from your device
|
47 |
+
4. Click Analyze to process the image
|
48 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|
|
50 |
if __name__ == "__main__":
|
51 |
+
demo.launch()
|