diff --git a/cloud/safety_checker.py b/cloud/safety_checker.py index 4c92808..08d8157 100644 --- a/cloud/safety_checker.py +++ b/cloud/safety_checker.py @@ -4,25 +4,31 @@ from APIs.aichat import generate import shared.config as config class DishSafetyResult(BaseModel): + visible_objects: list[str] = Field( + description="List EVERY distinct item visible in the frame (e.g., ['ceramic bowl', 'rice', 'metal spoon handle', 'stew'])." + ) + spoon_or_utensil_present: bool = Field( + description="Set to True if ANY metal, plastic, or wooden spoon, fork, knife, or utensil is present anywhere in or around the container." + ) is_safe: bool = Field( - description="Set to True if the dish contains ONLY normal food, rice, stew, and ceramic/glass/plastic bowls. Set to False ONLY if shiny metallic cutlery (spoon/fork/knife) or metallic foil is present." + description="Set to False if spoon_or_utensil_present is True, or if aluminum foil or metal is present. Set to True ONLY if pure food/bowl with zero utensils." ) detected_hazards: list[str] = Field( - description="List ONLY physical metal objects found (e.g., ['metal spoon']). If is_safe is True, this MUST be an empty list []." + description="List ONLY physical hazard items found (e.g., ['metal spoon']). Empty list [] if safe." ) warning_message: str = Field( - description="Clear warning if is_safe is False, otherwise empty string ''." + description="Warning statement if unsafe, otherwise empty string ''." ) def check_dish_safety(image_path: str) -> dict: prompt = ( - "You are a strict microwave safety vision inspector.\n\n" - "TASK: Inspect the top-down photo of the dish for ANY metal or plastic utensils (spoons, forks, knives, metal handles) or aluminum foil.\n\n" - "CRITICAL RULES:\n" - "1. Look closely at the edges and interior of the bowl for utensil handles sticking out, even if they appear dark or shadowed.\n" - "2. If you see ANY spoon handle, fork, knife, or utensil body—whether shiny silver, grey, or dark metal—mark is_safe = False.\n" - "3. ONLY mark is_safe = True if the bowl contains 100% food and rice with NO protruding utensils or foreign objects.\n" - "4. If a spoon or utensil is detected, set detected_hazards = ['metal spoon'] and warning_message = 'Please remove the metal utensil before microwaving.'" + "You are an expert microwave safety quality inspector analyzing a top-down camera frame.\n\n" + "INSPECTION STEPS:\n" + "1. Carefully examine the perimeter, edges, and inner cavity of the bowl/container.\n" + "2. Identify any utensil handles (spoons, forks, knives) protruding from or resting in the dish, regardless of shadow or reflectivity.\n" + "3. List all visible items in `visible_objects` first.\n" + "4. If a utensil or metal object is present anywhere, `spoon_or_utensil_present` MUST be True and `is_safe` MUST be False.\n" + "5. `is_safe` is True ONLY if the container holds strictly food with no utensils or metal." ) response_raw = generate(