Spaces:
Sleeping
Sleeping
axvg
commited on
Commit
·
ba09271
1
Parent(s):
e7246ce
init
Browse files- Dockerfile +16 -0
- app.py +33 -0
- haarcascade_frontalface_default.xml +0 -0
- requirements.txt +7 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Usa una imagen base de Python
|
2 |
+
FROM python:3.12.7
|
3 |
+
# Establece el directorio de trabajo
|
4 |
+
WORKDIR /code
|
5 |
+
|
6 |
+
# Copia los archivos necesarios al contenedor
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
9 |
+
RUN pip install fastapi uvicorn
|
10 |
+
|
11 |
+
COPY . .
|
12 |
+
|
13 |
+
RUN chmod -R 777 /code
|
14 |
+
|
15 |
+
# Comando para ejecutar la aplicación
|
16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
5 |
+
import cv2
|
6 |
+
from PIL import Image
|
7 |
+
import numpy as np
|
8 |
+
from io import BytesIO
|
9 |
+
|
10 |
+
app = FastAPI()
|
11 |
+
|
12 |
+
def buscar_existe(image):
|
13 |
+
existe = "NO"
|
14 |
+
print("resultado: ", image.shape)
|
15 |
+
eyeglasses_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
16 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
17 |
+
eyeglasses = eyeglasses_cascade.detectMultiScale(gray, 1.3, 5, minSize=(10, 10))
|
18 |
+
for (x, y, w, h) in eyeglasses:
|
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(...), rostro: str = Query(...)):
|
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))
|
haarcascade_frontalface_default.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
numpy
|
3 |
+
pydantic
|
4 |
+
opencv-python-headless
|
5 |
+
uvicorn[standard]
|
6 |
+
python-multipart
|
7 |
+
pillow
|