|
import cv2
|
|
from fastapi import FastAPI, File, UploadFile
|
|
import numpy as np
|
|
from PIL import Image
|
|
import io
|
|
|
|
app = FastAPI()
|
|
|
|
@app.post("/detect_disease/")
|
|
async def detect_disease(file: UploadFile = File(...)):
|
|
|
|
image_bytes = await file.read()
|
|
image = Image.open(io.BytesIO(image_bytes))
|
|
img_np = np.array(image)
|
|
|
|
|
|
gray = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
|
|
edges = cv2.Canny(gray, 100, 200)
|
|
|
|
|
|
disease_detected = "Enfermedad detectada" if np.mean(edges) > 50 else "Saludable"
|
|
|
|
return {"diagnosis": disease_detected}
|
|
|