Recipe Recommendation System Using Python
Last Updated :
17 Jan, 2024
In this article, we will explore how to build a Recipe Recommendation System using Streamlit and OpenAI. We will create the GUI using the Streamlit library and recommend the recipe by using the OpenAI API. We will see in this article how we can create the OpenAI API and use it on our Recipe Recommendation System using a Python app.
Recipe Recommendation System Using Python
Here, we will create the step-by-step implementation of the Recipe Recommendation System using Python. Let's start.
Step 1: Generate OpenAI API
Procedure to Obtain OpenAI API Key:
- Visit OpenAI's official website OpenAI Platform.
- Sign in to your existing account or create a new one if needed.
- Navigate to the API section: Upon signing in, locate and access the API section on the website.
- Create an API Key: Follow the provided instructions to generate a new API key.
- Once generated, securely copy the API key and store it for future use.
Step 2: Create Virtual Environment
Create the virtual environment using the commands below.
python -m venv env
.\env\Scripts\activate.ps1
File Strcutrue

Step 3: Install Necessary Libraries
First, install Streamlit for creating a graphical user interface (GUI), OpenAI to access the OpenAI API, and LangChain, which can be installed using the following command:
pip install streamlit
pip install openai
pip install langchain_community
Step 4: Import necessary libraries
Here, the code imports the Streamlit library as st
and the OpenAI
class from the langchain_community.llms
module.
import streamlit as st
from langchain_community.llms import OpenAI
Step 5: Implement the Logic
In this example , Python code creates a user friendly app that suggests recipes. Users enter their OpenAI API key on the side, list their favorite ingredients in a form, and click to get recipe ideas. The app uses OpenAI API to provide detailed recipes. If everything goes smoothly, it displays the suggested recipe. If there's an issue, the app shows an error message.
Python3
import streamlit as st
from langchain_community.llms import OpenAI
st.title('GeekCook ???? || Recipe Recommendation System')
openai_api_key = st.sidebar.text_input('OpenAI API Key')
def generate_recommendations(input_text):
try:
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key,
model="gpt-3.5-turbo-instruct")
prompt = f"Given the ingredients: {input_text
}, suggest an easy-to-cook step-by-step recipe."
response = llm(prompt)
return response
except Exception as e:
st.error(f"An error occurred: {str(e)}")
with st.form('my_form'):
user_input = st.text_area('Enter your preferred ingredients \
(separated by commas):')
submitted = st.form_submit_button('Get Recipe Recommendations')
if submitted and openai_api_key.startswith('sk-'):
recommended_recipe = generate_recommendations(user_input)
st.info(recommended_recipe)
Run the Server
streamlit run "app.py_file_path"
Output

Video Demonstration
Similar Reads
Health Management System using Python Sometimes we are so busy that we are not even able to care for our body and by caring we mean fitness, food, exercises and much more, and then we think that we need to make our diet plan or exercise plan to maintain our body. So let's make a Python script to maintain this record for us. In this prog
7 min read
Food Recognition Selenium using Caloriemama API Selenium is a powerful tool for controlling the web browser through a program. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. In this article, we are going to see how to automate the
2 min read
Boutique Management System using Python-MySQL Connectivity In this article, we are going to make a simple project on a boutique management system using Python MySql connectivity. Introduction This is a boutique management system made using MySQL connectivity with Python. It uses a MySQL database to store data in the form of tables and to maintain a proper r
15+ min read
Object oriented testing in Python Prerequisite: Object-Oriented Testing Automated Object-Oriented Testing can be performed in Python using Pytest testing tool. In this article, we perform object-oriented testing by executing test cases for classes. We write a program that has one parent class called Product and three child classes -
5 min read
Managing Cron Jobs Using Python Here, we will discover the significance of cron jobs and the reasons you require them in this lesson. You will examine python-crontab, a Python module that allows you to communicate with the crontab. What are Cron and Crontab?The utility known as Cron enables users to automatically run scripts, comm
6 min read
Create simple Blockchain using Python Blockchain is a time-stamped decentralized series of fixed records that contains data of any size and it is controlled by a large network of computers that are scattered around the globe and not owned by a single organization. Every block is secured and connected with each other using hashing techno
8 min read