Fix focus endpoint crash
This commit is contained in:
17
app/main.py
17
app/main.py
@@ -1,3 +1,5 @@
|
||||
from io import BytesIO
|
||||
|
||||
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
|
||||
from fastapi.responses import HTMLResponse, StreamingResponse
|
||||
from app.config import settings
|
||||
@@ -113,7 +115,18 @@ async def focus(
|
||||
|
||||
try:
|
||||
payload = await file.read()
|
||||
return process_image(payload, file.filename or "upload", buffer_ratio=buffer_ratio, detector=detector)
|
||||
result = process_image(payload, file.filename or "upload", buffer_ratio=buffer_ratio, detector=detector)
|
||||
return {
|
||||
"filename": result["filename"],
|
||||
"detector": result["detector"],
|
||||
"method": result["method"],
|
||||
"buffer_ratio": result["buffer_ratio"],
|
||||
"detected_bbox": result["detected_bbox"],
|
||||
"square_bbox": result["square_bbox"],
|
||||
"source_size": result["source_size"],
|
||||
"crop_data_url": result["crop_data_url"],
|
||||
"annotated_data_url": result["annotated_data_url"],
|
||||
}
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
@@ -129,6 +142,6 @@ async def focus_image(
|
||||
try:
|
||||
payload = await file.read()
|
||||
result = process_image(payload, file.filename or "upload", buffer_ratio=buffer_ratio, detector=detector)
|
||||
return StreamingResponse(result["crop_bytes_io"], media_type=result["mime_type"])
|
||||
return StreamingResponse(BytesIO(result["crop_bytes"]), media_type=result["mime_type"])
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
Reference in New Issue
Block a user