tarea 6 first commit
Browse files- Dockerfile +16 -0
- app.py +42 -0
- haarcascade_smile.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,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 SE DETECTO SONRISA"
|
| 14 |
+
print("resultado: ", image.shape)
|
| 15 |
+
|
| 16 |
+
# Cargar el clasificador de sonrisa
|
| 17 |
+
smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml')
|
| 18 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 19 |
+
|
| 20 |
+
# Detectar sonrisas
|
| 21 |
+
smiles = smile_cascade.detectMultiScale(
|
| 22 |
+
gray,
|
| 23 |
+
scaleFactor=1.7,
|
| 24 |
+
minNeighbors=22,
|
| 25 |
+
minSize=(25, 25)
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
for (x, y, w, h) in smiles:
|
| 29 |
+
existe = "SONRISA DETECTADA"
|
| 30 |
+
break
|
| 31 |
+
|
| 32 |
+
return existe
|
| 33 |
+
|
| 34 |
+
@app.post('/predict/')
|
| 35 |
+
async def predict(file: UploadFile = File(...), rostro: str = Query(...)):
|
| 36 |
+
try:
|
| 37 |
+
image = Image.open(BytesIO(await file.read()))
|
| 38 |
+
image = np.asarray(image)
|
| 39 |
+
prediction = buscar_existe(image)
|
| 40 |
+
return {"prediction": prediction}
|
| 41 |
+
except Exception as e:
|
| 42 |
+
raise HTTPException(status_code=500, detail=str(e))
|
haarcascade_smile.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
|