|
|
@@ -54,6 +54,30 @@ async def set_confidence(threshold: float = Body(..., embed=True)):
|
|
|
|
|
|
@app.post("/detect")
|
|
|
async def detect_ripeness(file: UploadFile = File(...)):
|
|
|
+ """Simple YOLO detection only. No archival or vectorization."""
|
|
|
+ image_bytes = await file.read()
|
|
|
+ img = Image.open(io.BytesIO(image_bytes))
|
|
|
+
|
|
|
+ results = yolo_model(img, conf=current_conf)
|
|
|
+
|
|
|
+ detections = []
|
|
|
+ for r in results:
|
|
|
+ for box in r.boxes:
|
|
|
+ detections.append({
|
|
|
+ "class": yolo_model.names[int(box.cls)],
|
|
|
+ "confidence": round(float(box.conf), 2),
|
|
|
+ "box": box.xyxy.tolist()[0]
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ "status": "success",
|
|
|
+ "current_threshold": current_conf,
|
|
|
+ "data": detections
|
|
|
+ }
|
|
|
+
|
|
|
+@app.post("/analyze")
|
|
|
+async def analyze_ripeness(file: UploadFile = File(...)):
|
|
|
+ """Full analysis: Detection + Vertex Vectorization + MongoDB Archival."""
|
|
|
# 1. Save file temporarily for YOLO and Vertex
|
|
|
temp_path = f"temp_{file.filename}"
|
|
|
with open(temp_path, "wb") as buffer:
|
|
|
@@ -73,10 +97,8 @@ async def detect_ripeness(file: UploadFile = File(...)):
|
|
|
"box": box.xyxy.tolist()[0]
|
|
|
})
|
|
|
|
|
|
- # 3. If detections found, analyze the first one (or all) for deeper insights
|
|
|
- results_summary = []
|
|
|
+ # 3. If detections found, analyze the first one (primary) for deeper insights
|
|
|
if detections:
|
|
|
- # For this MVP, we analyze the primary detection
|
|
|
primary_detection = detections[0]
|
|
|
record_id = analyze_use_case.execute(temp_path, primary_detection)
|
|
|
|
|
|
@@ -84,7 +106,7 @@ async def detect_ripeness(file: UploadFile = File(...)):
|
|
|
"status": "success",
|
|
|
"record_id": record_id,
|
|
|
"detections": detections,
|
|
|
- "message": "FFB processed and archived successfully"
|
|
|
+ "message": "FFB analyzed, vectorized, and archived successfully"
|
|
|
}
|
|
|
|
|
|
return {"status": "no_detection", "message": "No palm oil FFB detected"}
|