Skip to content

A Python version using Streamlit framework of the original Eat & Fit application.

Notifications You must be signed in to change notification settings

theEmperorofDaiViet/eat-and-fit.streamlit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents
  1. About The Project
  2. Getting Started
  3. Key Features
  4. Usage
  5. References
  6. Contact

  X  

About The Project

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.

Built With

  • Python
  • Streamlit
  • NumPy
  • [Matplotlib]
  • Markdown
  • HTML5
  • CSS3
  • SQLite

(back to top)

Getting Started

Prerequisites

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.

Installation

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:

Project Explorer

The first subfolder, which named algorithm, is a package containing the algorithm used in the project. In this case, I used Fuzzy Logic, so there is a Python file named fuzzy_logic.py to implement it. I defined a rule table as a 2-dimensional numpy array and provided functions to perform each step of Fuzzy Logic: fuzzification, fuzzy inference and defuzzification. In each function, I put some print() functions to print the calculations. When running the app, you can see the results in the terminal.

The second subfolder is database. The eatandfit.db file is the SQLite database of this application. You just need only it to use database in this app. But I still provided .sql files in the scripts subfolder to show the structure of each table in the database. You could modify these scripts and execute them to create another database that you want.

The third subfolder, images, contains the images used in this application. I stored all images of dishes as blob type in the database and used base64 to decode them back to .jpg images for displaying. But I still provided them in the dishes subfolder for you to check.

The fourth subfolder, which named models, is a package containing all the model class of this application. They are seperated into two .py files named eat.py and fit.py, respectively. The former consists of all the classes needed to make a diet plan, and the latter consists of all the classes needed to make a workout plan.

The final subfolder, which named pages, contains all .py files which will be loaded as pages by streamlit. Their names will be transformed to page names in the sidebar of the app.

And the last thing to focus on is the eat_and_fit.py file. It is the "main" file of this application and will be loaded as the home page. That's why we type it's name in the command to run the app.

(back to top)

Key Features

  • 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.

(back to top)

Usage

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.

(back to top)

References

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.

Contact

You can contact me via:


(back to top)

About

A Python version using Streamlit framework of the original Eat & Fit application.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages