Download app.py from Snigs98/ATM-Security-FaceRecognition: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/Snigs98/ATM-Security-FaceRecognition/resolve/main/app.py
- Command line
-
hf download hf://spaces/Snigs98/ATM-Security-FaceRecognition/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Snigs98/ATM-Security-FaceRecognition/resolve/main/app.py
1.99 kB
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| import random | |
| # OTP Setup | |
| OTP = random.randint(1000, 9999) | |
| # Face Detection using OpenCV | |
| face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") | |
| def detect_face(image): | |
| """Detects a face in an uploaded image.""" | |
| img_array = np.array(image) # Convert Gradio input to NumPy array | |
| gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY) | |
| faces = face_cascade.detectMultiScale(gray, 1.1, 4) | |
| if len(faces) > 0: | |
| return "β Face detected! Now enter your PIN." | |
| return "β No face detected! Please try again." | |
| def verify_pin(pin): | |
| """Checks if the entered PIN is correct.""" | |
| correct_pin = "1234" # Set your own PIN | |
| if pin == correct_pin: | |
| return f"β PIN correct! Your OTP is {OTP}. Please enter OTP." | |
| return "β Incorrect PIN. Try again." | |
| def verify_otp(otp): | |
| """Verifies the entered OTP.""" | |
| if str(otp) == str(OTP): | |
| return "β Access Granted! Welcome." | |
| return "β Incorrect OTP. Access Denied." | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π¦ ATM Security System π (Face + PIN + OTP)") | |
| # Face Detection | |
| img_input = gr.Image(type="numpy", label="Upload Your Image for Face Detection") | |
| detect_button = gr.Button("π Detect Face") | |
| face_result = gr.Textbox(label="Face Detection Status") | |
| detect_button.click(fn=detect_face, inputs=img_input, outputs=face_result) | |
| # PIN Verification | |
| pin_input = gr.Textbox(label="Enter PIN", type="password") | |
| pin_button = gr.Button("π Submit PIN") | |
| pin_result = gr.Textbox(label="PIN Status") | |
| pin_button.click(fn=verify_pin, inputs=pin_input, outputs=pin_result) | |
| # OTP Verification | |
| otp_input = gr.Textbox(label="Enter OTP") | |
| otp_button = gr.Button("π’ Submit OTP") | |
| otp_result = gr.Textbox(label="OTP Status") | |
| otp_button.click(fn=verify_otp, inputs=otp_input, outputs=otp_result) | |
| demo.launch() | |