Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,37 @@
|
|
| 1 |
-
import
|
| 2 |
-
import numpy as np
|
| 3 |
-
from keras.models import load_model
|
| 4 |
-
from keras.preprocessing import image
|
| 5 |
-
from PIL import Image
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from keras.models import load_model
|
| 4 |
+
from keras.preprocessing import image
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# Load model
|
| 8 |
+
model = load_model("Face Detector.keras")
|
| 9 |
+
|
| 10 |
+
# Prediction function
|
| 11 |
+
def predict_mask(img):
|
| 12 |
+
if img is None:
|
| 13 |
+
return "No image provided"
|
| 14 |
+
|
| 15 |
+
img = img.resize((200, 200))
|
| 16 |
+
img_array = image.img_to_array(img)
|
| 17 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 18 |
+
img_array = img_array / 255.0
|
| 19 |
+
|
| 20 |
+
pred = model.predict(img_array)[0][0]
|
| 21 |
+
|
| 22 |
+
if pred < 0.5:
|
| 23 |
+
return "✅ Mask is Detected"
|
| 24 |
+
else:
|
| 25 |
+
return "🚫 Mask is NOT Detected"
|
| 26 |
+
|
| 27 |
+
# Interface
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=predict_mask,
|
| 30 |
+
inputs=gr.Image(source="webcam", tool="editor", type="pil"),
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="😷 Face Mask Detection App",
|
| 33 |
+
description="Use your webcam or upload an image to check if a face mask is present."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
iface.launch()
|