Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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)
|
| 9 |
+
|
| 10 |
+
# Face Detection using OpenCV
|
| 11 |
+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 12 |
+
|
| 13 |
+
def detect_face(frame):
|
| 14 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 15 |
+
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
|
| 16 |
+
return len(faces) > 0 # Returns True if a face is detected
|
| 17 |
+
|
| 18 |
+
def capture_face():
|
| 19 |
+
cap = cv2.VideoCapture(0) # Open Webcam
|
| 20 |
+
face_detected = False
|
| 21 |
+
while not face_detected:
|
| 22 |
+
ret, frame = cap.read()
|
| 23 |
+
if not ret:
|
| 24 |
+
continue
|
| 25 |
+
face_detected = detect_face(frame)
|
| 26 |
+
if face_detected:
|
| 27 |
+
cap.release()
|
| 28 |
+
return "Face detected! Enter PIN."
|
| 29 |
+
|
| 30 |
+
def verify_pin(pin):
|
| 31 |
+
correct_pin = "1234" # Set your own PIN
|
| 32 |
+
if pin == correct_pin:
|
| 33 |
+
return f"PIN correct! Your OTP is {OTP}. Please enter OTP."
|
| 34 |
+
return "Incorrect PIN. Try again."
|
| 35 |
+
|
| 36 |
+
def verify_otp(otp):
|
| 37 |
+
if str(otp) == str(OTP):
|
| 38 |
+
return "Access Granted! Welcome."
|
| 39 |
+
return "Incorrect OTP. Access Denied."
|
| 40 |
+
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
gr.Markdown("# ATM Security System 🚀 (Face + PIN + OTP)")
|
| 43 |
+
|
| 44 |
+
webcam = gr.Button("Start Face Detection")
|
| 45 |
+
result = gr.Textbox(label="Status")
|
| 46 |
+
|
| 47 |
+
webcam.click(fn=capture_face, outputs=result)
|
| 48 |
+
|
| 49 |
+
pin_input = gr.Textbox(label="Enter PIN", type="password")
|
| 50 |
+
pin_button = gr.Button("Submit PIN")
|
| 51 |
+
pin_result = gr.Textbox(label="PIN Status")
|
| 52 |
+
|
| 53 |
+
pin_button.click(fn=verify_pin, inputs=pin_input, outputs=pin_result)
|
| 54 |
+
|
| 55 |
+
otp_input = gr.Textbox(label="Enter OTP")
|
| 56 |
+
otp_button = gr.Button("Submit OTP")
|
| 57 |
+
otp_result = gr.Textbox(label="OTP Status")
|
| 58 |
+
|
| 59 |
+
otp_button.click(fn=verify_otp, inputs=otp_input, outputs=otp_result)
|
| 60 |
+
|
| 61 |
+
demo.launch()
|