DasariHarshitha commited on
Commit
4f1e8fa
Β·
verified Β·
1 Parent(s): a81a425

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -1,37 +1,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()
 
 
 
 
 
 
 
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")