Food Recommender System with recipe and justification generation for Semantics in Intelligent Information Access and Recommender Systems @ Università degli Studi di Bari Aldo Moro, AY 2024/25
The Food Recommender System is designed to provide personalized recipe recommendations and generate justifications for the recommendations. This project is part of Semantics in Intelligent Information Access course and Recommender Systems course at Università degli Studi di Bari Aldo Moro for the academic year 2024/25.
The system's architecture includes multiple components, each responsible for different aspects of meal recommendation and justification. Below is a breakdown of the system's key modules and functionalities:
- User Profiler: Captures and updates user preferences, intolerances, and meal history.
- Meal Generator: Creates meals based on user preferences, available ingredients, and nutritional data.
- Justificator: Provides reasoning behind meal recommendations, including nutritional benefits.
- Mood Module: Suggests meals based on the user’s mood, e.g., recommending comfort foods if the user is stressed.
- Seasonal Recommendations: Encourages consumption of seasonal ingredients based on environmental and health benefits.
In the docs folder you can find the following documentation:
food-recsys-docs.md: Food Recommender System (Standalone ver.) Documentationfood-recsys-api-docs.md: FastAPI API Documentationfood-recsys-demo-docs.md: Streamlit Demo Documentation
You can consult these files also clicking on the badges in this section or at the top of the page.
Information about the data provided in this repository can be found in the Datasets section of the system documentation.
The project is structured as follows:
food-recommender-system/
|
├── data/ <-- Contains datasets and user profiles*
| ├── processed/ <-- Saving folder for user profiles*
| ├── raw/ <-- Folder with datasets used by the system*
| | ├── food-infos.json <-- Informations about seasonal produces*
| | ├── food-seasonality.json <-- National seasonal foods*
| | ├── food-servings.json <-- LARN's italian serving sizes and frequencies*
| | └── nutritional-facts.csv <-- Nutritional dataset*
| |
├── docs/ <-- Docs about the system, the API and the demo
| ├── food-recsys-docs.md
| ├── food-recsys-api-docs.md
| └── food-recsys-dmeo-docs.md
|
├──food_recommender_system/
| ├── demo/ <--- Streamlit Demo folder
| | ├── pages/
| | | ├── 1_home.py <-- Create or Load User Profiles
| | | ├── 2_user_profile.py <-- Shows User Profile Informations
| | | └── 3_meal_selection.py <-- Select between original and recommended meals
| | |
| | └── main.py <-- Launches the Streamlit demo
| |
| ├── fastapi/ <-- FastAPI API folder
| | ├── api.py <-- API endpoints logic
| | ├── main.py <-- Launches the API on localhost:8000
| | └── utils.py <-- Useful functions for the API
| |
| ├── config.py <-- Contains all constants and Paths*
| ├── dataloader.py <-- Manages JSON, CSV and other files*
| ├── justificator.py <-- Persuasion logic for recommended meals*
| ├── main.py <-- Launches the standalone system with CLI interface*
| ├── mealgen.py <-- Generates meals based starting from preferences*
| ├── moodmod.py <-- Module related to cheat meals*
| ├── profiler.py <-- Manages UserProfile objects*
| └── recommender.py <-- Functions to retrieve similar foods*
|
├── references/ <-- EFSA, CREA and LARN reference documents
| ├── efsa-summary.pdf
| └── porzioni-larn.pdf
|
├── LICENSE
├── Makefile
├── metrics.json <-- Saves statistics and ratings about the system*
├── pyproject.toml
├── README.md
├── requirements.txt
└── setup.cfg
Note: folders and fiels with * symbol are necessary in order to let the system work
- Create or load a user profile with preferences, intolerances and meals
- Ask for seasonal and non-seasonal preferences to generate meals
- Recommend similar food with lower energy density from the same category or not
- Once per week, ask the user if wants to have a cheat meal
- Show useful information about seasonal and local fruits and vegetables
To install the Food Recommender System, follow these steps:
-
Clone the repository:
git clone https://github.com/molinari135/food-recommender-system.git
-
Navigate to the project directory:
cd food-recommender-system -
Install the required dependencies:
pip install -r requirements.txt
To use the Food Recommender System, run the following command:
python food_recommender_system/main.pyThe system provides a standard profile named default. You can also define a new username and it will be added automatically.
The following is an example of usage of the system using the CLI interface.
If you do not write any number during the preferences selection, the system will load default choices.
If you do not write any number during the seasonal preference selection, the system will load every seasonal food.
Follow the on-screen instructions to get personalized recipe recommendations.
- Create or Load User: This option allows to load a different user or create a new one, as in the beginning of the application.
- Display Current Meal and Alternatives: Using system's calendar and clock, this option will show the current meal of the day and, if needed, will ask the user to choose the actual meal by selecting a food for each section proposed. Then, it will be saved in the user's profile.
- Display Weekly Meal Plan: This option will show the entire generated weekly plan with breakfasts, snacks, lunches and dinners. The first meal shown is the one generated starting from user's preferences, then it will show an alternative version with a lower energy density (which is the standardized ratio between calories and weight). It will also display the actual user choice made between each food of the same meal.
- Learn About Seasonal Food: Using your system's calendar, this option will show the user every seasonal fruit and vegetables alongside useful informations such as how to choose them, how to store them, how to cook them, some nutritional informations and benefits and also some tips.
Example of loading the profile lactose:
Example of menu showing after creating or loading a profile:
Printing the generated weekly meal plan:
Or creating the CSV version of the plan:
Example of current meal and justificator triggering:
Seasonality function that shows all seasonal produces for the current month:
Example of information provided for a seasonal food:
The system has a GUI demo made with Streamlit that can be tested by running the following command:
streamlit run food_recommender_system/demo/main.pyit will automatically open the demo in your browser. If you want to try the demo without installing anything, you can reach it at this link that will redirect to Hugging Face Spaces, were it is hosted.
This demo relies on an API hosted in another Hugging Face Spaces. The Swagger UI can be reached at this link.
Spaces automatically shut down after 48h of inactivity; if the system is not working or the API is "down", please send me an email at e.molinari3@studenti.uniba.it
The demo has the same functionality as the standalone version and has the following initial screen:
In the main page of the Streamlit demo are shown the Recommender Performances. They are very useful to understand how well the recommender is performing overall:
- Win Rate: Percentage of times the recommender system's suggestion was chosen.
- Rejection Rate: Percentage of times the user rejected the recommender system's suggestion.
- Avg. Persuasion Rating: Average rating given by the user for the persuasion message of the recommendation.
All these informations are obtained during runtime and saved in metrics.json file that can be accessed every time and contains the following informations:
recsys_wins: number of times in which the recommended food has been chosen instead of the preferred fooduser_wins: number of times in which the preferred food has been chosen instead of the recommended foodjustification_success: for now, same as therecsys_wins(for future uses)total_choices: total number of choices that users have been made from the launch of the systempersuasion_satisfaction: a list with ratings from 1 to 5 that express the review of the overall comparison between preferred and recommended foods
This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.
For a copy of the license, please visit https://creativecommons.org/licenses/by-nc/4.0/
This system was designed and implemented by Ester Molinari (@molinari135), MSc student in Computer Science @ University of Bari Aldo Moro during AY 2024/2025.









