File size: 1,045 Bytes
ba09271
 
 
 
 
 
 
 
 
 
 
 
1dd5ec4
ba09271
 
 
 
 
738ed99
ba09271
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 = False
    print("resultado: ", image.shape)
    eyeglasses_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    eyeglasses = eyeglasses_cascade.detectMultiScale(gray, 1.3, 5, minSize=(10, 10))
    for (x, y, w, h) in eyeglasses:
        existe = True
        break

    return existe

# Ruta de predicción
@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))