File size: 3,581 Bytes
a31f556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""

modules/chef.py β€” FRIDAY Chef Assistant



Recipe help and cooking:

- Recipe suggestions

- Cooking guidance

- Ingredient substitutions

- Meal planning

"""

import random


# Quick Recipes
QUICK_MEALS = [
    {"name": "Pasta Aglio e Olio", "time": "15 min", "ingredients": "pasta, garlic, olive oil, chili"},
    {"name": "Grilled Cheese", "time": "10 min", "ingredients": "bread, cheese, butter"},
    {"name": "Chicken Stir Fry", "time": "20 min", "ingredients": "chicken, veggies, soy sauce"},
    {"name": "Omelette", "time": "10 min", "ingredients": "eggs, cheese, veggies"},
    {"name": "BLT Sandwich", "time": "10 min", "ingredients": "bread, bacon, lettuce, tomato"},
]


def suggest_meal(mood: str = "") -> str:
    """Suggest meal based on mood."""
    if "quick" in mood or "fast" in mood:
        meal = random.choice(QUICK_MEALS)
        return f"{meal['name']} - {meal['time']}. Needs: {meal['ingredients']}"

    if "comfort" in mood:
        return "Grilled Cheese or Mac and Cheese. Comfort food."

    if "healthy" in mood:
        return "Chicken stir fry with veggies, or salad."

    return random.choice(QUICK_MEALS)["name"]


def find_recipe(dish: str) -> str:
    """Find quick recipe for dish."""
    try:
        from config import GEMINI_API_KEY, GEMINI_MODEL
        if not GEMINI_API_KEY:
            return "No API. Try: pasta aglio e olio"

        import google.generativeai as genai
        genai.configure(api_key=GEMINI_API_KEY)
        model = genai.GenerativeModel(GEMINI_MODEL)

        prompt = f"Quick recipe for {dish} in 3 simple steps."
        resp = model.generate_content(prompt)
        return resp.text.strip()[:300]
    except Exception:
        return f"Recipe for {dish}: Google it."


def substitute(ingredient: str) -> str:
    """Find substitute for ingredient."""
    subs = {
        "butter": "coconut oil or applesauce",
        "egg": "flax egg (1tbsp flax + 3tbsp water)",
        "milk": "oat milk or almond milk",
        "flour": "almond flour or coconut flour",
        "sugar": "honey or maple syrup",
        "cream": "coconut cream",
        "sour cream": "greek yogurt",
    }

    ingredient_lower = ingredient.lower()
    for orig, sub in subs.items():
        if orig in ingredient_lower:
            return f"Use {sub} instead of {ingredient}."

    return f"No substitute known for {ingredient}."


# ── Voice Commands ────────────────────────────────────────────

def handle_command(command: str, speak) -> bool:
    """Handle chef commands."""
    c = command.lower()

    if "cook" in c or "recipe" in c or "food" in c or "meal" in c:
        # What to cook
        if "what to cook" in c or "suggest" in c or "can't decide" in c:
            meal = suggest_meal(c)
            speak(f"How about: {meal}")
            return True

        # Recipe for X
        if "recipe for" in c or "how to make" in c:
            dish = c.replace("recipe for", "").replace("how to make", "").strip()
            if dish:
                result = find_recipe(dish)
                speak(result[:200])
                return True

        # Substitutions
        if "substitute" in c or "替代" in c:
            ing = c.replace("substitute", "").replace("instead of", "").strip()
            if ing:
                result = substitute(ing)
                speak(result)
                return True

    return False