Upload app.py
Browse files123456789101112131415161718192021222324252627282930import gradio as grfrom tensorflow.keras.models import model_from_jsonimport numpy as npimport cv2
# Load the model architecture and weightswith open('antispoofing_model.json', 'r') as json_file: loaded_model_json = json_file.read()model = model_from_json(loaded_model_json)model.load_weights('antispoofing_model.h5')
# Load the face detection modelface_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def predict(image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: face = image[y:y+h, x:x+w] face = cv2.resize(face, (160, 160)) face = face.astype('float') / 255.0 face = np.expand_dims(face, axis=0) pred = model.predict(face) label = 'Spoof' if pred > 0.5 else 'Real' cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) cv2.putText(image, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) return image
iface = gr.Interface(fn=predict, inputs="image", outputs="image")iface.launch()app.pyAdded+30