Compare commits
2 Commits
f0ae0839b0
...
93c1c8e299
| Author | SHA1 | Date | |
|---|---|---|---|
| 93c1c8e299 | |||
| 6629dd9472 |
+23
-11
@@ -31,6 +31,7 @@ db = client["microwave_network_db"]
|
|||||||
|
|
||||||
cooking_collection = db["cooking_parameters"]
|
cooking_collection = db["cooking_parameters"]
|
||||||
telemetry_collection = db["telemetry_data"]
|
telemetry_collection = db["telemetry_data"]
|
||||||
|
alert_collection = db["alert_data"]
|
||||||
|
|
||||||
# Ensure the camera image storage directory exists when the app starts
|
# Ensure the camera image storage directory exists when the app starts
|
||||||
CAMERA_IMAGE_DIR = "storage/dishPhotos"
|
CAMERA_IMAGE_DIR = "storage/dishPhotos"
|
||||||
@@ -105,18 +106,9 @@ async def cooking_params():
|
|||||||
current_app.logger.exception("Exception during safety check or cook planning")
|
current_app.logger.exception("Exception during safety check or cook planning")
|
||||||
return jsonify({"error": f"Task execution failed: {str(e)}"}), 500
|
return jsonify({"error": f"Task execution failed: {str(e)}"}), 500
|
||||||
|
|
||||||
# 3. Evaluate Safety Result
|
|
||||||
data["safety_check"] = safety_result
|
|
||||||
if not safety_result.get("is_safe", True):
|
|
||||||
current_app.logger.warning(f"Unsafe dish detected: {safety_result}")
|
|
||||||
return jsonify({
|
|
||||||
"error": "Safety hazard detected in microwave area",
|
|
||||||
"is_safe": False,
|
|
||||||
"warning": safety_result.get("warning_message", "Unsafe materials detected."),
|
|
||||||
"detected_hazards": safety_result.get("detected_hazards", [])
|
|
||||||
}), 200
|
|
||||||
|
|
||||||
# 4. Attach Cooking Plan & Save to MongoDB
|
# 4. Attach Cooking Plan & safety check and Save to MongoDB
|
||||||
|
data["safety_check"] = safety_result
|
||||||
data["analysis_results"] = cook_plan
|
data["analysis_results"] = cook_plan
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -125,10 +117,30 @@ async def cooking_params():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": f"Database error: {str(e)}"}), 500
|
return jsonify({"error": f"Database error: {str(e)}"}), 500
|
||||||
|
|
||||||
|
# 3. Evaluate Safety Result
|
||||||
|
if not safety_result.get("is_safe", True):
|
||||||
|
current_app.logger.warning(f"Unsafe dish detected: {safety_result}")
|
||||||
|
return jsonify({
|
||||||
|
"error": "Safety hazard detected in microwave area",
|
||||||
|
"is_safe": False,
|
||||||
|
"warning_message": safety_result.get("warning_message", "Unsafe materials detected."),
|
||||||
|
"detected_hazards": safety_result.get("detected_hazards", [])
|
||||||
|
}), 200
|
||||||
|
|
||||||
return jsonify(cook_plan), 201
|
return jsonify(cook_plan), 201
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception("Exception in /cooking-params")
|
current_app.logger.exception("Exception in /cooking-params")
|
||||||
|
|
||||||
|
@app.route("/alert", methods=["POST"])
|
||||||
|
def alert():
|
||||||
|
# Save the alert in alert_collection
|
||||||
|
data = request.get_json()
|
||||||
|
alert_collection.insert_one(data)
|
||||||
|
|
||||||
|
# TODO : Créer une room webex et envoyer un sms
|
||||||
|
|
||||||
|
return jsonify({"status": "success", "message": "Alert saved"}), 200
|
||||||
|
|
||||||
@app.route("/telemetry", methods=["POST"])
|
@app.route("/telemetry", methods=["POST"])
|
||||||
def telemetry():
|
def telemetry():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class DishSafetyResult(BaseModel):
|
|||||||
def check_dish_safety(image_path: str) -> dict:
|
def check_dish_safety(image_path: str) -> dict:
|
||||||
prompt = (
|
prompt = (
|
||||||
"Analyze this top-down photo of a dish prepared for microwave cooking. "
|
"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 that could be dangerous for the cooking process or pose a safety risk."
|
"Inspect the area for metal utensils, aluminum foil, metallic dish patterns, or unvented plastic wraps that could be dangerous for the dish microwave cooking process or pose a safety risk."
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2. Pass the Pydantic class directly to generate()
|
# 2. Pass the Pydantic class directly to generate()
|
||||||
|
|||||||
Reference in New Issue
Block a user