feat(backend): endpoint POST /api/identify PlantNet + YOLO fallback + cache

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 12:18:56 +01:00
parent 2e67e9cb02
commit 560fa63a45
2 changed files with 60 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
from fastapi import APIRouter, File, UploadFile
from app.services import plantnet, yolo_service, redis_cache
router = APIRouter(tags=["identification"])
@router.post("/identify")
async def identify_plant(file: UploadFile = File(...)):
image_bytes = await file.read()
# 1. Cache Redis
cached = redis_cache.get(image_bytes)
if cached is not None:
return {"source": "cache", "results": cached}
# 2. PlantNet (cloud)
results = await plantnet.identify(image_bytes, file.filename or "photo.jpg")
# 3. Fallback YOLO si PlantNet indisponible
if not results:
results = await yolo_service.identify(image_bytes)
source = "yolo"
else:
source = "plantnet"
# 4. Mettre en cache
redis_cache.set(image_bytes, results)
return {"source": source, "results": results}