Upload 2 files
Browse files- app.py +28 -0
- face_mask_model.h5 +3 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
import uvicorn
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import numpy as np
|
| 5 |
+
import cv2
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
|
| 11 |
+
# Load model
|
| 12 |
+
model = tf.keras.models.load_model("Face_Mask_Model.h5")
|
| 13 |
+
labels = ["Mask", "No Mask"]
|
| 14 |
+
|
| 15 |
+
@app.post("/predict")
|
| 16 |
+
async def predict(file: UploadFile = File(...)):
|
| 17 |
+
image = Image.open(BytesIO(await file.read())).convert("RGB")
|
| 18 |
+
image = image.resize((128, 128)) # match your input shape
|
| 19 |
+
img_array = np.array(image).astype("float32") / 255.0
|
| 20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 21 |
+
|
| 22 |
+
pred = model.predict(img_array)[0]
|
| 23 |
+
result = {labels[i]: float(pred[i]) for i in range(len(labels))}
|
| 24 |
+
|
| 25 |
+
return {"prediction": result}
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
face_mask_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e58f27a464bbb54f3ab23abd17c846dea867d047d6904ba1df894eacdea0e98a
|
| 3 |
+
size 39704352
|