Files
Smartwave/cloud/safety_checker.py
T
Ninluc 980d79b793
Build, push image, and notify Watchtower / build-image (push) Successful in 38s
Build, push image, and notify Watchtower / notify (push) Successful in 9s
Fix str passed to json
2026-08-10 17:02:41 +02:00

44 lines
1.4 KiB
Python

import json
from APIs.aichat import generate
DISH_SAFETY_SCHEMA = {
"type": "object",
"properties": {
"is_safe": {
"type": "boolean",
"description": "True if no microwave hazards (metal, foil, sealed packaging) are present."
},
"warning_message": {
"type": "string",
"description": "Explanation of any hazard found, or an empty string if safe."
},
"detected_hazards": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of specific hazard items detected."
}
},
"required": ["is_safe", "warning_message", "detected_hazards"]
}
def check_dish_safety(image_path: str) -> dict:
prompt = (
"Analyze this top-down photo of a dish prepared for microwave cooking. "
"Inspect the area for metal utensils, aluminum foil, metallic dish patterns, or unvented plastic wraps."
)
# Pass the schema directly to the generation call
response_raw = generate(
prompt=prompt,
images=[image_path],
output_format=json.dumps(DISH_SAFETY_SCHEMA)
)
print(f"[Debug] Raw response from AI generator: {response_raw}")
# 1. If response_raw is already a dict, return it directly
if isinstance(response_raw, dict):
return response_raw
raise ValueError(f"Unexpected response type from AI generator: {type(response_raw)}")