Snigs98's picture
Update app.py
ed6a945 verified
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()