The app recommends recipes based on the input ingredients and favourite recipes.
The recommender uses Content Based Filtering that uses the characteristics of items to make a recommendation for a user (see figure 1).
Figure 1: Content Based Filtering
The figure 1 shows two favorite recipes of a user. A mushroom soup with parsley and a noodles with meatballs in tomato sauce. Based on the ingredients of theses two favorite recipes the user gets a recommendation for a new recipe. The recommendation is a noodle soup with spring onions.
The Cosine Similarity is the metric to measure the similarity between documents or in this case recipes. A value of 0 means no similarity and a value of 1 full similarity. In the following example a 2 dimensional vector space is used.
Figure 2: Cosine Similarity between banana and milk
The figure 2 shows in one dimension a banana and in the other a milk. The angle between both is 90° and the resulting value for the cosine is 0. That means that the banana has no similarity with a milk. But what happens if you mix a banana and milk to a banana shake.
Figure 3: Cosine Similarity between banana shake and milk
Due to the fact that the banana shake is a mixure of a banana and a milk the vector is between those two ingredients/products in figure 3. Therefore the angle for the banana shake between the milk (also banana shake to banana) is 45° and the resulting value for the cosine is 0.707.
The database used for this project is PostgreSQL. The following image shows the schema of the database.
Ingredients
The ingredients
table contains all ingredient used for the recipes.
id
(string): hash generated id based on the ingredient nanename
(string): name of the ingredient
Recipes
The recipes
table contains the basic information of all recipes.
id
(string): given id for the recipe combined of incremented number and originname
(string): title of the recipeenergy_kj
(float): kilo joule per portion for the recipeenergy_kcal
(float): kilo calories per portion for the recipefat
(float): amount of fat per portion for the recipesat_fat
(float): amount of saturated fat per portion for the recipecarbs
(float): amount of carbs per portion for the recipesugar
(float): amount of sugar per portion for the recipeprotein
(float): amount of protein per portion for the recipesalt
(float): amount of salt per portion for the recipepreparation
(integer): time to prepare the recipedifficulty
(string): difficulty to prepare to the recipe
RecipeLinks
The recipe_links
table links the recipes to the ingredients with amounts and units.
id
(string): hash generated id based on therecipe_id
,ingredient_id
,amount
andunit
recipe_id
(string): id of the recipeingredient_id
(string): id of the ingredientamount
(float): amount of the ingredientunit
(string): unit of the amount
RecipeSteps
The recipe_steps
table contains the steps to prepare each recipe.
id
(string): hash generated id based on therecipe_id
,step
andtext
.recipe_id
(string): id of the recipestep
(integer): number of the steptext
(string): text of the current step
Users
The users
table contains all the user information.
id
(integer): increasing integer starting from 1name
(string): name of the user
UserFavorites
The user_favorites
table contains all favorite recipes of the users.
id
(string): hash generated id based on theuser_id
andrecipe_id
user_id
(string): id of the userrecipe_id
(string): id of the recipe
This repository is currently not providing any recipe data for the database.
The necessary packages used to run the application are in the requirements.txt
and installed as follows:
pip install -r requirements.txt
The information to connect to the database are stored in the .env
file and has the following structure:
POSTGRES_USER='user'
POSTGRES_PASSWORD='password'
POSTGRES_HOST='127.0.0.1'
POSTGRES_PORT='5432'
POSTGRES_DB='database name'
The recipe recommender is using streamlit to run the application on a web browser. To run the
application the following command needs to be executed:
streamlit run app.py
If the command is not executed inside the folder of the app, please add the path (~/path/app.py
)
The following animation shows the basic functionality of the recipe recommender.
- Choose the ingredients you want to use
- Set the amount of recommended recipes you want to receive
- Push recommend recipes to get recommendations
- Select a recipe and push eat recipe to see full information