AI-Powered Recipe Generator: Solving the “What’s for Dinner?” Dilemma
As someone who loves cooking, I often found myself staring blankly into the refrigerator, struggling to decide what to make for dinner.
Sound familiar? This common culinary conundrum led me to develop a solution: an AI-powered Recipe Generator that combines my personal preferences with the vast world of recipes available online.
The Inspiration
Like many food enthusiasts, I have a diverse palate and enjoy cuisines from around the world. However, this variety sometimes made it challenging to choose what to cook on any given day. I realized that what I needed was a tool that could:
- Remember my favorite cuisines and ingredients
- Consider my dietary restrictions
- Suggest meals based on my preferences
- Allow me to search for specific recipes when I had something in mind
With these goals in mind, I set out to create a program that would automate my decision-making process for cooking.
The Solution: AI-Powered Recipe Generator
I developed a Python-based application using Dash, a framework for building analytical web applications. The Recipe Generator has two main components:
- An AI-powered meal suggestion feature
- A recipe search function using the Tasty API
Here’s an overview of how it works:
AI Meal Suggestion
The AI meal suggestion feature uses OpenAI’s GPT-4 model to generate personalized meal ideas. It takes into account:
- My preferred cuisines (stored in an Excel workbook)
- Dietary restrictions
- Favorite ingredients
- Other preferences
Users can select which cuisines they’re in the mood for using a checklist, giving them control over the AI’s suggestions.
Recipe Search
For times when I have a specific dish in mind, the application includes a recipe search function. This feature uses the Tasty API to find recipes based on:
- Search query
- Specific ingredients
- Minimum user rating
The Code
import pandas as pd
from openai import OpenAI
import requests
import random
import dash
from dash import dcc, html
from dash.dependencies import Input, Output, State
# ... (API key setup and other initializations)
def get_ai_meal_suggestion(user_name, selected_cuisines):
user_prefs = next((item for item in food_db if item["User Name"] == user_name), None)
if not user_prefs:
return "User not found in the database."
prompt = f"Suggest a meal for {user_name} considering the following parameters:\n\n"
prompt += f"1. Selected cuisines: {', '.join(selected_cuisines)}\n"
prompt += f"2. Dietary restrictions: {user_prefs['Dietary Restrictions']}\n"
prompt += f"3. Favorite ingredients: {user_prefs['Favorite Ingredients']}\n"
prompt += f"4. Other preferences: {user_prefs['Other Preferences']}\n\n"
prompt += "Please provide a meal suggestion that fits these criteria."
return get_chatgpt_response(prompt)
def get_recipe_from_api(query, ingredients=None, min_rating=None):
# ... (API call to Tasty)
app.layout = html.Div([
html.H1('Recipe Generator'),
dcc.Input(id='user-input', type='text', placeholder='Enter your name'),
html.Div([
html.H3('Select Cuisines:'),
dcc.Checklist(
id='cuisine-checklist',
options=[{'label': cuisine, 'value': cuisine} for cuisine in all_cuisines],
value=all_cuisines,
inline=True
)
]),
html.Button('Get AI Meal Suggestion', id='ai-suggestion-button'),
html.Div(id='ai-suggestion-output'),
html.Hr(),
dcc.Input(id='manual-query', type='text', placeholder='Enter your recipe search query'),
dcc.Input(id='ingredient-input', type='text', placeholder='Enter ingredients (comma-separated)'),
dcc.Input(id='min-rating-input', type='number', placeholder='Minimum user rating', min=0, max=5, step=0.1),
html.Button('Search Recipe', id='search-button'),
html.Div(id='recipe-output'),
])
# ... (Callback functions for AI suggestion and recipe search)
if __name__ == '__main__':
app.run_server(debug=True)
The Result
With this Recipe Generator, I’ve significantly reduced the time and mental energy spent on deciding what to cook. On days when I’m feeling indecisive, I simply input my name, select the cuisines I’m interested in, and let the AI suggest a meal. When I have a specific craving or ingredient to use, I can quickly search for relevant recipes.
This project not only solved my personal “what’s for dinner” dilemma but also demonstrated the practical applications of AI in everyday life. By combining personal data (my food preferences) with AI and public APIs, I created a tool that makes cooking decisions easier and more enjoyable.
Whether you’re a seasoned chef or a cooking novice, tools like this can help inspire your culinary adventures and take some of the stress out of meal planning. Happy cooking!