Abhi-22 commited on
Commit
95981ec
·
verified ·
1 Parent(s): 55f4e33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -68
app.py CHANGED
@@ -2,83 +2,50 @@ import gradio as gr
2
  import numpy as np
3
  import time
4
 
5
- def placeholder_process(image):
6
  """Placeholder function - replace with your backend integration"""
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
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
- 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):
46
- gr.Markdown("""
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
- 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
83
  if __name__ == "__main__":
84
- demo.launch(share=True)
 
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()