Enhance image before ai processing
Build, push image, and notify Watchtower / build-image (push) Successful in 41s
Build, push image, and notify Watchtower / notify (push) Successful in 14s

This commit is contained in:
2026-08-23 12:33:39 +02:00
parent 6b8c1688a6
commit 3711928c7d
3 changed files with 63 additions and 3 deletions
+16
View File
@@ -2,6 +2,7 @@ import json
from pydantic import BaseModel, Field
from APIs.aichat import generate
import shared.config as config
from PIL import Image, ImageEnhance
class UtensilMaterialCheck(BaseModel):
object_name: str = Field(
@@ -28,6 +29,21 @@ class DishSafetyResult(BaseModel):
description="If is_safe is False, set to 'REMOVE METAL UTENSIL OR FOIL BEFORE MICROWAVING'. Otherwise empty ''."
)
def preprocess_dish_image(image_path: str) -> str:
"""Brightens dark areas and sharpens food texture for small vision models."""
img = Image.open(image_path)
# 1. Boost brightness slightly
enhancer = ImageEnhance.Brightness(img)
img = enhancer.enhance(1.4)
# 2. Boost contrast to separate food shapes from dark shadows
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(1.3)
processed_path = "/tmp/processed_dish.jpg"
img.save(processed_path, quality=85)
return processed_path
def check_dish_safety(image_path: str) -> dict:
prompt = (