Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,35 @@
|
|
| 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 |
-
# Load model
|
| 8 |
model = load_model("Face Detector.keras")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 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 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
from keras.models import load_model
|
| 4 |
from keras.preprocessing import image
|
| 5 |
from PIL import Image
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
# Load the trained model
|
| 9 |
model = load_model("Face Detector.keras")
|
| 10 |
|
| 11 |
+
st.title("π· Face Mask Detection App")
|
| 12 |
+
st.write("Upload an image and check if the person is wearing a mask.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# File uploader
|
| 15 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 16 |
|
| 17 |
+
if uploaded_file is not None:
|
| 18 |
+
# Show uploaded image
|
| 19 |
+
img = Image.open(uploaded_file)
|
| 20 |
+
st.image(img, caption="Uploaded Image", use_column_width=True)
|
| 21 |
|
| 22 |
+
# Preprocess image
|
| 23 |
+
img = img.resize((200, 200))
|
| 24 |
+
img = image.img_to_array(img)
|
| 25 |
+
img = np.expand_dims(img, axis=0)
|
| 26 |
+
img = img / 255.0
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Predict
|
| 29 |
+
prediction = model.predict(img)[0][0]
|
| 30 |
+
|
| 31 |
+
# Result
|
| 32 |
+
if prediction < 0.5:
|
| 33 |
+
st.success("β
Mask is Detected")
|
| 34 |
+
else:
|
| 35 |
+
st.error("π« Mask is NOT Detected")
|