"title"=>"Recipe Mixer",
"summary"=>nil,
"content"=>"
Recipe Mixer is an AI-powered web application that encourages culinary exploration through recipe remixing. Users can input a recipe or list ingredients they have on hand, and the application utilizes the Gemini Pro model to suggest alternative ingredients based on flavor profiles and user preferences, including dietary restrictions.
Why use Recipe Mixer?
Recipe Mixer is a user-friendly web application that helps you find delicious recipes based on the ingredients you have on hand. Whether you’re a busy parent, a cooking enthusiast, or someone with dietary restrictions, Recipe Mixer makes meal planning easy and enjoyable.
All you need to do is input the ingredients you have in your kitchen and specify any dietary preferences you may have, such as vegetarian or gluten-free. Recipe Mixer then suggests personalized recipe options that match your input. It even offers alternative ingredient suggestions and can adapt recipes to different cultural cuisines, so you can explore new flavors and cooking styles.
With Recipe Mixer, you no longer have to worry about what to cook for dinner or how to use up leftover ingredients. It’s like having a personal chef at your fingertips, ready to inspire you with creative and delicious meal ideas.
Features
- Ingredient Matching: Users can input a list of ingredients they have on hand, and the application suggests recipes based on those ingredients.
- Dietary Preferences: Users can specify dietary preferences such as vegetarian, vegan, or gluten-free, and the suggested recipes take these preferences into account.
- Alternative Ingredient Suggestions: The application suggests alternative ingredients based on flavor profiles and dietary preferences, allowing users to experiment with different ingredients.
- Cultural Adaptation: The suggested recipes can be adapted to different cultural cuisines, promoting culinary exploration and diversity.
Dependencies
- Gemini Pro LLM: Natural language processing model for text classification.
- Streamlit: Web application framework for building interactive web applications.
- Google Generative AI: Integrates advanced AI capabilities into the application.
- python-dotenv: python-dotenv is a Python library that allows you to read environment variables from .env files.
- langchain.llms: langchain.llms is a library used to interact with language models, particularly for text generation tasks.
How it works?
Building Recipe Mixer🧑🏻🍳
Requirements:
- Python 3.10
- Gemini Pro API key (Note: Ensure you have the necessary credentials and permissions to access the Gemini Pro API)
Steps:
- Clone the repository
git clone https://github.com/Gitesh08/recipe-mixer.git
or create app.py file and paste below code.
import streamlit as st
import google.generativeai as genai
from dotenv import load_dotenv
import os
# Load environment variables from a .env file
load_dotenv()
# Configure the generative AI model with the Google API key
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Set up the model configuration for text generation
generation_config = {
"temperature": 0.4,
"top_p": 1,
"top_k": 32,
"max_output_tokens": 4096,
}
# Create a GenerativeModel instance with 'gemini-pro' as the model type
llm = genai.GenerativeModel(
model_name="gemini-pro",
generation_config=generation_config,
)
def match_ingredients(user_ingredients, dietary_preferences=None):
"""
Matches ingredients with recipes using Gemini Pro (if available).
Args:
user_ingredients (list): List of user-provided ingredients (lowercase and stripped).
dietary_preferences (str, optional): User's dietary preferences (e.g., vegetarian, vegan).
Returns:
tuple: A tuple containing the recipe name and instructions (if found), otherwise None.
"""
prompt_template = """Find a delicious recipe using these ingredients: {ingredients}.
{dietary_preferences_prompt}
I want the response in a single structured format."""
dietary_preferences_prompt = f"Considering dietary restrictions: {dietary_preferences}" if dietary_preferences else ""
prompt = prompt_template.format(ingredients=", ".join(user_ingredients), dietary_preferences_prompt=dietary_preferences_prompt)
response = llm.generate_content(prompt)
# Parse the response from Gemini Pro to extract the matching recipe name and instructions (implementation depends on API response format)
recipe = response.text
# ... (code to parse response and extract recipe information)
return recipe
st.set_page_config(page_title="Recipe Mixer")
st.title("Recipe Mixer" + ":sunglasses:")
st.markdown('<style>h1{color: orange; text-align: center; font-family:POPPINS}</style>', unsafe_allow_html=True)
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
user_ingred = st.text_input("Enter your ingredients (comma-separated):")
# Add dietary preference dropdown
dietary_options = st.selectbox("Dietary Preferences (Optional):", [None, "Vegetarian", "Vegan", "Gluten-Free"])
submit_button = st.button("Suggest me recipe")
user_ingredients = user_ingred.split(", ")
if submit_button:
if user_ingred is not None:
# Preprocess user ingredients
user_ingredients_str = [ingredient.strip().lower() for ingredient in user_ingred.split(", ")]
# Call match_ingredients once and assign results
recipe = match_ingredients(user_ingredients_str, dietary_preferences=dietary_options)
if recipe:
complete_recipe = f"\\n{recipe}\\n"
st.write(complete_recipe.replace('\\\\n', '\\n'))
else:
st.write("No Recipe")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
st.text(" \\n")
footer="""<style>
a:link , a:visited{
color: yellow;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color: red;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: Bottom;
left: 0;
bottom: 0;
width: 100%;
background-color: transparent;
color: white;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with ❤ by<a style='display: block; text-align: center;' href="https://github.com/Gitesh08" target="_blank">Gitesh Mahadik</a></p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)
Create file requirements.txt and paste below code.
streamlit
google-generativeai
python-dotenv
langchain
2. Create a Python virtual environment. Open a new terminal of your editor and paste below command.
python -m virtualenv .
3. Activate virtual environment. Paste below command in terminal.
.\\scripts\\activate
4. Install the required dependencies.
pip install -r requirements.txt
5. Generate Gemini Pro API Key:
Build with the Gemini API | Google AI for Developers
6. Create .env file and define your API Key.
GOOGLE_API_KEY = "Replace with your API Key"
7. Run the application.
streamlit run app.py
Access the application through your web browser using the provided local address.
Great! You have successfully built Recipe Mixer using the Gemini Pro LLM model.
Please give a star to this repo!
GitHub - Gitesh08/Recipe-Mixer
Usage
- Input your ingredients: Enter a list of ingredients you have on hand, separated by commas.
- Specify dietary preferences (optional): Select your dietary preferences from the dropdown menu.
- Click the “Suggest me recipe” button to receive recipe suggestions.
- Explore alternative ingredient suggestions and recipe options.
- Enjoy experimenting with different recipes and ingredients!
Contributions are welcome! If you have any suggestions, enhancements, or bug fixes, feel free to open an issue or submit a pull request.
Thank you for reading! I hope you enjoyed this article. If you did, please consider subscribing to my Medium publication. You can also follow me on LinkedIn for more updates.
If you have any questions or feedback, please feel free to leave a comment below. I would love to hear from you!
Recipe Mixer🧑🏻🍳 was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
","author"=>"Gitesh Mahadik",
"link"=>"https://medium.com/google-cloud/recipe-mixer-88fe60836e43?source=rss----e52cf94d98af---4",
"published_date"=>Fri, 05 Apr 2024 04:51:23.000000000 UTC +00:00,
"image_url"=>nil,
"feed_url"=>"https://medium.com/google-cloud/recipe-mixer-88fe60836e43?source=rss----e52cf94d98af---4",
"language"=>nil,
"active"=>true,
"ricc_source"=>"feedjira::v1",
"created_at"=>Fri, 05 Apr 2024 08:04:19.112031000 UTC +00:00,
"updated_at"=>Tue, 14 May 2024 04:56:25.716450000 UTC +00:00,
"newspaper"=>"Google Cloud - Medium",
"macro_region"=>"Blogs"}