Spaces:
Running
Running
| """ | |
| 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 |