mpuneeth17 commited on
Commit
eb2d6af
·
verified ·
1 Parent(s): a27919c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from huggingface_hub import hf_hub_download
6
+ from PIL import Image
7
+
8
+ CLASSES = ["with_mask", "without_mask", "mask_worn_incorrectly"]
9
+ LABELS = {
10
+ "with_mask": "✅ Mask Worn Correctly",
11
+ "without_mask": "❌ No Mask",
12
+ "mask_worn_incorrectly": "⚠️ Mask Worn Improperly",
13
+ }
14
+
15
+ # Load model from Hub
16
+ model_path = hf_hub_download(repo_id="mpuneeth17/face-mask-detection", filename="face_mask_model.h5")
17
+ model = tf.keras.models.load_model(model_path)
18
+
19
+ def predict(image):
20
+ img = Image.fromarray(image).resize((224, 224))
21
+ arr = np.expand_dims(np.array(img), 0).astype("float32") / 255.0
22
+ pred = model.predict(arr, verbose=0)[0]
23
+ return {LABELS[cls]: float(conf) for cls, conf in zip(CLASSES, pred)}
24
+
25
+ demo = gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.Image(label="Upload face image", type="numpy"),
28
+ outputs=gr.Label(num_top_classes=3, label="Mask Detection Result"),
29
+ title="🎭 Face Mask Detection AI",
30
+ description="Upload a face image to detect whether a mask is worn correctly, not worn, or worn improperly.\n\nPowered by MobileNetV2 + TensorFlow.",
31
+ examples=[],
32
+ theme=gr.themes.Soft(primary_hue="indigo"),
33
+ allow_flagging="never",
34
+ )
35
+
36
+ demo.launch()