Answer with cooking plan and save edamam API tokens
This commit is contained in:
+13
-3
@@ -5,6 +5,7 @@ from flask import Flask, request, jsonify
|
||||
from pymongo import MongoClient
|
||||
from APIs import generate, EdamamAPI
|
||||
import sys
|
||||
from microwaveCookPlanner import MicrowaveCookPlanner
|
||||
sys.path.insert(0, '..')
|
||||
try:
|
||||
from shared import config
|
||||
@@ -28,6 +29,11 @@ device_network_collection = db["device_network"]
|
||||
CAMERA_IMAGE_DIR = "storage/dishCameraImages"
|
||||
os.makedirs(CAMERA_IMAGE_DIR, exist_ok=True)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Classes
|
||||
# ---------------------------------------------------------
|
||||
microwave_cook_planner = MicrowaveCookPlanner()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Routes
|
||||
# ---------------------------------------------------------
|
||||
@@ -72,14 +78,18 @@ def cooking_params():
|
||||
|
||||
# Remove the Mongo-injected '_id' object before returning the response
|
||||
data.pop("_id", None)
|
||||
return jsonify({"message": "Cooking parameters saved successfully", "data": data}), 201
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": f"Database error: {str(e)}"}), 500
|
||||
|
||||
# 3. Returns with the cooking parameters
|
||||
|
||||
|
||||
cooking_plan = microwave_cook_planner.generate_plan(
|
||||
image_path=data.get("camera_image"),
|
||||
height_cm=data.get("height_cm", 4.0),
|
||||
initial_temp_c=data.get("initial_temp_c", 20.0),
|
||||
microwave_wattage=data.get("microwave_wattage", 900)
|
||||
)
|
||||
return jsonify(cooking_plan), 201
|
||||
|
||||
@app.route("/device-network", methods=["POST"])
|
||||
def device_network():
|
||||
|
||||
Reference in New Issue
Block a user