Calorie Contra
Demo
Description
This calorie counter and food search web app is for individuals who want to track their calories and macros throughout the day and week. For searching data, it uses a REST API from the USDA FDC API. It is also embedded with a chatbot that helps you achieve your goals.
Usage
-
Clone this repository
git clone https://github.com/jericho1050/calorie-contra.git -
Create a virtual environment
virtualenv envor
python -m venv envthen activate it
# MacOS source env/bin/activate# Windows .\env\Scripts\activate -
Install the dependencies
pip install -r requirements.txt -
Create a
.envfile for API keys and secret variables# .env api_key = "your_api_key_here" # https://fdc.nal.usda.gov/api-key-signup.html SECRET_KEY = "your_secret_key_here" gemini_api_key = "your_api_key_here" # https://ai.google.dev -
Run the server
python app.py
Walkthrough
app.py Routes
/home (GET, POST)
- Purpose: Displays the search form and handles search queries.
- Methods:
GET: Renders the home page.POST: Processes the search query and redirects to the search results.
/search (GET)
- Purpose: Returns a list of foods matching the search query.
- Methods:
GET: Renders the search results page.
/api/search_foods (GET)
- Purpose: API endpoint to search for foods using the USDA FoodData Central API.
- Methods:
GET: Returns JSON data of the search results.
/login (GET, POST)
- Purpose: Logs the user in.
- Methods:
GET: Renders the login page.POST: Authenticates the user and starts a session.
/register (GET, POST)
- Purpose: Registers a new user.
- Methods:
GET: Renders the registration page.POST: Processes the registration form and creates a new user.
/logout (GET)
- Purpose: Logs the user out.
- Methods:
GET: Clears the session and redirects to the home page.
/food/<int:id> (GET)
- Purpose: Displays the selected food's nutrition facts.
- Methods:
GET: Renders the food details page.
/food-log (GET, POST)
- Purpose: Displays and updates the user's food log.
- Methods:
GET: Renders the food log page.POST: Adds a new food entry to the user's log.
/generate (POST)
- Purpose: Generates a response using the generative AI model.
- Methods:
POST: Processes the user's input and returns the AI-generated response.
Test
TODO
Contribution Guideline
TODO
