Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, File, UploadFile, HTTPException | |
from fastapi.responses import HTMLResponse | |
from pydantic import BaseModel | |
from typing import List | |
from PIL import Image | |
import numpy as np | |
from io import BytesIO | |
import cv2 | |
app = FastAPI() | |
def buscar_gato(image): | |
existe = "No existe el GATO " | |
print("resultado: ", image.shape) | |
# Cargar el clasificador Haar para gatos | |
face_cascade = cv2.CascadeClassifier('haarcascade_frontalcatface.xml') | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
faces_rect = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=9) | |
#cats = cat_cascade.detectMultiScale(gray, 1.3, 5, minSize=(10, 10)) | |
existe = "No hay persona" | |
for (x, y, w, h) in faces_rect: | |
existe = "Si hay persona" | |
break | |
return existe | |
async def predict(file: UploadFile = File(...)): | |
try: | |
image = Image.open(BytesIO(await file.read())) | |
image = np.asarray(image) | |
prediction = buscar_gato(image) | |
return {"prediction": prediction} | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) |