Table of Contents
A Python version using Streamlit framework of the original Eat & Fit application - a simple knowledge based system using Fuzzy Logic to provide weight-loss guide consist of a diet plan and a workout plan based on user's current state.
Warning: The diagnosis of body fatness and the weight-loss plan generated by this application is just imitation for programming purpose. You should not follow them. To get the right instructions, you should use actual weight-loss applications, or better yet, go to the doctor.
Before cloning and using this application, you'll need to install these things on your computer:
- Python 3.10.2: Streamlit is a app framework in Python language, so you need to have Python installed to run this application. I used Python 3.10.2, but I think it works fine with some other releases as well.
- Visual Studio Code: You can choose any IDE or Text Editor that you want. To build a simple application like this, I recommend Visual Studio Code.
- Streamlit: a free and open-source framework to rapidly build and share beautiful machine learning and data science web apps. Open the terminal and type this command to install Streamlit:
pip install streamlit
- NumPy: a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. Open the terminal and type this command to install Numpy:
pip install numpy
- Matplotlib: a comprehensive library for creating static, animated, and interactive visualizations in Python. Open the terminal and type this command to install Matplotlib:
pip install matplotlib
- SQLite: a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.
- SQLiteStudio: a desktop application for browsing and editing SQLite database files. It is aimed for people, who know what SQLite is, or what relational databases are in general.
You can install this application by cloning this repository into your current working directory:
git clone https://github.com/theEmperorofDaiViet/eat-and-fit.streamlit.git
After cloning the repository, you can open the project by Visual Studio Code. To run the application, open a terminal and type:
streamlit run eat_and_fit.py
As usual, the app should automatically open in a new tab in your browser. It runs on port 8501 by default.
Fast enough, huh? Let's stop for a while and take a look at the project's structure:
- Get and validate user input
- Process input by Fuzzy Logic to determine user's current state
- Provide a weight-loss plan based on user's state:
- A diet plan consist of 3 different types of eating days per week: low, moderate and high carb
- A workout plan of cardio and gym
- A "eat" page to search for food and recipe if the user want to know how to cook the dish in the diet plan.
- A "fit" page to search for exercise if the user want to know exactly how to do it.
This is a short video, which converted to gif, to illustrate the features of the application in a nutshell:
- The home page includes a sidebar to navigate through other pages and enter input. The default input is male, 175 cm in height, 80 kg in weight and beginner.
- I change the weight to 50 kg and click the "Submit" button. My Fuzzy Logic considers a man with that height and weight to be "underweight". The application display a message to advise me to gain weight, not to lose weight.
- Then, I change the weight to 65 kg and click "Submit". My Fuzzy Logic considers a man with that height and weight to be "normal". The application display a message to advise me to maintain that healthy weight.
- This time I change the weight to 80 kg and click "Submit" again. My Fuzzy Logic considers a man with that height and weight to be "overweight". A message is displayed to inform my current state, and followed by the weight-loss plan provided for me.
- The plan consists of:
- A diet plan with three menus for low, moderate, and high carb eating days. Each menu consists of nutrition info; a pie chart represent the percentage of calories from carbs, fat and protein; and dish for each meal.
- A workout plan of cardio and gym.
- Then, I change the stage to "intermediate". You can see the plan is changed! Once the first plan is generated, you don't need to click the submit button, just change the input and the plan will be automatically changed according to the input you entered.
- After that, I navigate to the 🍱 eat page and search for a salmon recipe. There are several matched results, I choose Roasted Salmon. The page displays all about that recipe:
- Dish's image
- Nutrition info
- Ingredients
- Steps to cook
- Then, I navigate to the 🏋️♂️ fit page and search for an exercise for leg. There are several matched results, I choose Leg Extension. The page displays a video guide, overview and specific instructions to do the exercise.
- Finally, I go back to the home page. The input and the plan are still here! I used some workaround with
st.session_state
and callback to keep input value during navigating through other pages.
I want to say a big thanks to Eat This Much and Muscle & Strength. I used some of their knowledge in diet and workout to build this project, but I also adjusted these knowledge a bit to match my programming idea. So, again:
Warning: DO NOT trust in the plan in this application. You should go to Eat This Much and Muscle & Strength's website to see the RIGHT instructions.
You can contact me via: