Spaces:
Sleeping
Sleeping
File size: 1,061 Bytes
6555f40 35de7c8 d09b132 6555f40 4652f1b 2c194f5 6555f40 2c194f5 6555f40 2c194f5 6555f40 2c194f5 6555f40 4652f1b 6555f40 d09b132 6555f40 2c194f5 6555f40 d09b132 3402a2e b469bad d09b132 6555f40 2c194f5 6555f40 2c194f5 d09b132 2c194f5 | 1 2 3 4 5 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 36 37 38 39 40 41 | import gradio as gr
import tensorflow as tf
import numpy as np
import cv2
# Load the SavedModel
model = tf.keras.models.load_model("mask_mobilenet_savedmodel")
def predict_mask(image):
try:
# Convert RGBA to RGB if needed
if image.shape[2] == 4:
image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
# Resize and normalize
image = cv2.resize(image, (224, 224))
image = image / 255.0
image = np.expand_dims(image, axis=0)
# Use the 'call' method instead of calling the object
preds = model.call(tf.convert_to_tensor(image), training=False).numpy()
result = "Mask" if preds[0][0] > 0.5 else "No Mask"
return result
except Exception as e:
print("Error:", e)
return f"Error: {e}"
# Gradio interface
iface = gr.Interface(
fn=predict_mask,
inputs=gr.Image(type="numpy"),
outputs="text",
title="Mask Detection",
description="Upload an image to check if a person is wearing a mask."
)
if __name__ == "__main__":
iface.launch()
|