feat(image-to-text): clean json export to image_file and prompt only, sort queue sequentially by filename, and auto-resize images >720px on upload

This commit is contained in:
2026-10-29 13:27:57 +05:30
parent eb7b549785
commit 47c35da17e
4 changed files with 280 additions and 54 deletions
+6
View File
@@ -178,6 +178,8 @@ def generate(req: GenerateRequest):
raise HTTPException(status_code=404, detail=f"Image file not found: {req.image_path}")
try:
image = Image.open(img_path).convert("RGB")
if max(image.width, image.height) > 720:
image.thumbnail((720, 720), Image.Resampling.LANCZOS)
except Exception as exc:
raise HTTPException(status_code=400, detail=f"Failed to read image: {exc}")
elif req.image_base64:
@@ -187,6 +189,8 @@ def generate(req: GenerateRequest):
raw_data = raw_data.split(",", 1)[1]
img_bytes = base64.b64decode(raw_data)
image = Image.open(io.BytesIO(img_bytes)).convert("RGB")
if max(image.width, image.height) > 720:
image.thumbnail((720, 720), Image.Resampling.LANCZOS)
except Exception as exc:
raise HTTPException(status_code=400, detail=f"Failed to decode base64 image: {exc}")
else:
@@ -289,6 +293,8 @@ def _execute_batch_job(job_id: str, req: BatchStartRequest):
t0 = time.time()
try:
img = Image.open(img_path).convert("RGB")
if max(img.width, img.height) > 720:
img.thumbnail((720, 720), Image.Resampling.LANCZOS)
text = model.generate(
image_input=img,
prompt=effective_prompt,