Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
import random
|
| 5 |
-
from twilio.rest import Client # For OTP (optional, needs Twilio API)
|
| 6 |
|
| 7 |
# OTP Setup
|
| 8 |
OTP = random.randint(1000, 9999)
|
|
@@ -11,21 +10,14 @@ OTP = random.randint(1000, 9999)
|
|
| 11 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 12 |
|
| 13 |
def detect_face(image):
|
|
|
|
| 14 |
img_array = np.array(image) # Convert Gradio input to NumPy array
|
| 15 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 16 |
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
with gr.Blocks() as demo:
|
| 20 |
-
gr.Markdown("# ATM Security System π (Face + PIN + OTP)")
|
| 21 |
-
|
| 22 |
-
img_input = gr.Image(type="numpy", label="Upload Your Image for Face Detection")
|
| 23 |
-
detect_button = gr.Button("Detect Face")
|
| 24 |
-
result = gr.Textbox(label="Detection Result")
|
| 25 |
-
|
| 26 |
-
detect_button.click(fn=detect_face, inputs=img_input, outputs=result)
|
| 27 |
-
|
| 28 |
-
demo.launch()
|
| 29 |
def verify_pin(pin):
|
| 30 |
"""Checks if the entered PIN is correct."""
|
| 31 |
correct_pin = "1234" # Set your own PIN
|
|
@@ -41,19 +33,23 @@ def verify_otp(otp):
|
|
| 41 |
|
| 42 |
# Gradio UI
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
-
gr.Markdown("# π¦ ATM Security System (Face + PIN + OTP)
|
| 45 |
-
|
| 46 |
-
webcam = gr.Button("π· Start Face Detection")
|
| 47 |
-
result = gr.Textbox(label="Face Detection Status")
|
| 48 |
-
|
| 49 |
-
webcam.click(fn=capture_face, outputs=result)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
pin_input = gr.Textbox(label="Enter PIN", type="password")
|
| 52 |
pin_button = gr.Button("π Submit PIN")
|
| 53 |
pin_result = gr.Textbox(label="PIN Status")
|
| 54 |
|
| 55 |
pin_button.click(fn=verify_pin, inputs=pin_input, outputs=pin_result)
|
| 56 |
-
|
|
|
|
| 57 |
otp_input = gr.Textbox(label="Enter OTP")
|
| 58 |
otp_button = gr.Button("π’ Submit OTP")
|
| 59 |
otp_result = gr.Textbox(label="OTP Status")
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
import random
|
|
|
|
| 5 |
|
| 6 |
# OTP Setup
|
| 7 |
OTP = random.randint(1000, 9999)
|
|
|
|
| 10 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 11 |
|
| 12 |
def detect_face(image):
|
| 13 |
+
"""Detects a face in an uploaded image."""
|
| 14 |
img_array = np.array(image) # Convert Gradio input to NumPy array
|
| 15 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 16 |
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
|
| 17 |
+
if len(faces) > 0:
|
| 18 |
+
return "β
Face detected! Now enter your PIN."
|
| 19 |
+
return "β No face detected! Please try again."
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def verify_pin(pin):
|
| 22 |
"""Checks if the entered PIN is correct."""
|
| 23 |
correct_pin = "1234" # Set your own PIN
|
|
|
|
| 33 |
|
| 34 |
# Gradio UI
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("# π¦ ATM Security System π (Face + PIN + OTP)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Face Detection
|
| 39 |
+
img_input = gr.Image(type="numpy", label="Upload Your Image for Face Detection")
|
| 40 |
+
detect_button = gr.Button("π Detect Face")
|
| 41 |
+
face_result = gr.Textbox(label="Face Detection Status")
|
| 42 |
+
|
| 43 |
+
detect_button.click(fn=detect_face, inputs=img_input, outputs=face_result)
|
| 44 |
+
|
| 45 |
+
# PIN Verification
|
| 46 |
pin_input = gr.Textbox(label="Enter PIN", type="password")
|
| 47 |
pin_button = gr.Button("π Submit PIN")
|
| 48 |
pin_result = gr.Textbox(label="PIN Status")
|
| 49 |
|
| 50 |
pin_button.click(fn=verify_pin, inputs=pin_input, outputs=pin_result)
|
| 51 |
+
|
| 52 |
+
# OTP Verification
|
| 53 |
otp_input = gr.Textbox(label="Enter OTP")
|
| 54 |
otp_button = gr.Button("π’ Submit OTP")
|
| 55 |
otp_result = gr.Textbox(label="OTP Status")
|