Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List
|
|
@@ -9,7 +9,7 @@ from io import BytesIO
|
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
-
def buscar_existe(imagen):
|
| 13 |
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
| 14 |
#imagen = cv2.imread('carro.jpg')
|
| 15 |
gray = cv2.cvtColor(imagen, cv2.COLOR_BGR2GRAY)# convierte a tono de gris
|
|
@@ -19,15 +19,15 @@ def buscar_existe(imagen):
|
|
| 19 |
existe = "Si"
|
| 20 |
break
|
| 21 |
|
| 22 |
-
return existe
|
| 23 |
|
| 24 |
# Ruta de predicci贸n
|
| 25 |
@app.post('/predict/')
|
| 26 |
-
async def predict(file: UploadFile = File(...)):
|
| 27 |
try:
|
| 28 |
image = Image.open(BytesIO(await file.read()))
|
| 29 |
image = np.asarray(image)
|
| 30 |
-
prediction = buscar_existe(image)
|
| 31 |
return {"prediction": prediction}
|
| 32 |
except Exception as e:
|
| 33 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException, Query
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List
|
|
|
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
+
def buscar_existe(imagen, mensaje):
|
| 13 |
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
| 14 |
#imagen = cv2.imread('carro.jpg')
|
| 15 |
gray = cv2.cvtColor(imagen, cv2.COLOR_BGR2GRAY)# convierte a tono de gris
|
|
|
|
| 19 |
existe = "Si"
|
| 20 |
break
|
| 21 |
|
| 22 |
+
return existe+" "+mensaje
|
| 23 |
|
| 24 |
# Ruta de predicci贸n
|
| 25 |
@app.post('/predict/')
|
| 26 |
+
async def predict(file: UploadFile = File(...), mensaje: str = Query(...)):
|
| 27 |
try:
|
| 28 |
image = Image.open(BytesIO(await file.read()))
|
| 29 |
image = np.asarray(image)
|
| 30 |
+
prediction = buscar_existe(image, mensaje)
|
| 31 |
return {"prediction": prediction}
|
| 32 |
except Exception as e:
|
| 33 |
raise HTTPException(status_code=500, detail=str(e))
|