File size: 1,156 Bytes
e627a7f |
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 42 43 |
from fastapi import FastAPI, File, UploadFile, HTTPException, Query
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
from typing import List
import cv2
from PIL import Image
import numpy as np
from io import BytesIO
app = FastAPI()
def buscar_existe(image):
existe = "NO SE DETECTO SONRISA"
print("resultado: ", image.shape)
# Cargar el clasificador de sonrisa
smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detectar sonrisas
smiles = smile_cascade.detectMultiScale(
gray,
scaleFactor=1.7,
minNeighbors=22,
minSize=(25, 25)
)
for (x, y, w, h) in smiles:
existe = "SONRISA DETECTADA"
break
return existe
@app.post('/predict/')
async def predict(file: UploadFile = File(...), rostro: str = Query(...)):
try:
image = Image.open(BytesIO(await file.read()))
image = np.asarray(image)
prediction = buscar_existe(image)
return {"prediction": prediction}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
|