Upload 3 files
Browse files- Dockerfile +28 -0
- app.py +23 -0
- requirements.txt +7 -0
Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Usa una imagen base de Python con soporte para TensorFlow
|
2 |
+
FROM tensorflow/tensorflow:2.11.0
|
3 |
+
|
4 |
+
# Establece el directorio de trabajo
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Instala dependencias del sistema
|
8 |
+
RUN apt-get update && apt-get install -y \
|
9 |
+
libgl1-mesa-glx \
|
10 |
+
libglib2.0-0
|
11 |
+
|
12 |
+
# Copia el archivo requirements.txt al contenedor
|
13 |
+
COPY ./requirements.txt /app/requirements.txt
|
14 |
+
|
15 |
+
# Instala dependencias de Python
|
16 |
+
RUN pip install --no-cache-dir -r /app/requirements.txt
|
17 |
+
|
18 |
+
# Copia el c贸digo fuente de la aplicaci贸n al contenedor
|
19 |
+
COPY . /app
|
20 |
+
|
21 |
+
# Asigna permisos de ejecuci贸n a los scripts (opcional)
|
22 |
+
RUN chmod -R 777 /app
|
23 |
+
|
24 |
+
# Expone el puerto para la API
|
25 |
+
EXPOSE 7860
|
26 |
+
|
27 |
+
# Comando para ejecutar la aplicaci贸n
|
28 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
from fastapi import FastAPI, File, UploadFile
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
@app.post("/detect_disease/")
|
10 |
+
async def detect_disease(file: UploadFile = File(...)):
|
11 |
+
# Leer imagen cargada
|
12 |
+
image_bytes = await file.read()
|
13 |
+
image = Image.open(io.BytesIO(image_bytes))
|
14 |
+
img_np = np.array(image)
|
15 |
+
|
16 |
+
# Convertir a escala de grises y aplicar an谩lisis de bordes
|
17 |
+
gray = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
|
18 |
+
edges = cv2.Canny(gray, 100, 200)
|
19 |
+
|
20 |
+
# Analizar caracter铆sticas b谩sicas (esto es un ejemplo)
|
21 |
+
disease_detected = "Enfermedad detectada" if np.mean(edges) > 50 else "Saludable"
|
22 |
+
|
23 |
+
return {"diagnosis": disease_detected}
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
numpy
|
4 |
+
Pillow
|
5 |
+
opencv-python
|
6 |
+
tensorflow
|
7 |
+
python-multipart
|