Skip to content

ChetanyaRathi/Virtual-AI-Trainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual AI Trainer & Nutritionist Web App 🧠💪🍎

🚀 Overview

This is a personalized web application designed to act as a virtual fitness trainer and nutritionist. Users log their daily activities, meals, and other health metrics. An AI analyzes this data to provide personalized insights, recommendations, and eventually, workout/meal plans.

This project includes a Python (FastAPI) backend and a React frontend.


✨ Core Features Implemented

  • Secure Authentication:
    • Sign up with Email/Password.
    • Log in with Email/Password.
    • Continue with Google (OAuth 2.0).
    • Secure JWT-based session management.
  • User Onboarding:
    • Collects user profile data (age, weight (kg), height (cm), goal, activity level) after first login.
  • Comprehensive Data Logging:
    • Log daily workouts (title, details).
    • Log daily meals (title, details, calories, protein).
    • Log daily sleep (hours, quality, stress level).
    • Log current weight (kg).
  • Interactive Dashboard & Navigation:
    • Multi-page structure using React Router (Home, Insights, Chat, History, Charts).
    • Responsive Navbar with hamburger menu for mobile.
    • Home Page: Displays all logging forms (Workout, Meal, Sleep, Weight).
    • History Page: Shows scrollable lists of logged workouts, meals, sleep, and weight entries with delete functionality.
    • Charts Page: Visualizes trends for Calories/Protein, Sleep Duration, and Weight Change using Chart.js.
  • AI Integration (Google Gemini):
    • Insights: Generates personalized insights based on user profile and recent logs on the Insights page. Includes insight history display.
    • Chatbot: Provides a conversational interface on the Chat page, using user data and chat history for contextual responses.
  • Data Persistence & Logging:
    • SQLite Database: Stores user accounts, profiles, all log entries, and chat history.
    • Activity Logging: Records key user actions (signup, login) in the activity_logs table.
    • AI Interaction Logging: Saves AI insight prompts/responses in the ai_prompt_logs table. Chat history is stored separately.

🛠️ Tech Stack & Rationale

  • Backend:
    • Framework: FastAPI (Python) - High performance, async support, data validation, API docs.
    • Database: SQLite - Simple, file-based for development. Uses SQLAlchemy (ORM).
    • Authentication: Passlib (hashing), Python-JOSE (JWT), Authlib (Google OAuth), Starlette Sessions.
    • AI: Google Generative AI SDK (Vertex AI) - For interacting with Gemini models.
    • Web Server: Uvicorn - Standard ASGI server.
    • Environment: Python Virtual Environment (venv).
  • Frontend:
    • Library: React - Component-based UI development.
    • Build Tool: Vite - Fast development server and build process.
    • Routing: react-router-dom - For SPA navigation.
    • Styling: Plain CSS - Using App.css and Navbar.css for custom styling.
    • Charting: react-chartjs-2 & chart.js - For data visualization.
    • Package Manager: npm.
  • Development:
    • Editor: VS Code
    • Version Control: Git

⚙️ Setup and Running

Prerequisites:

  • Python (3.10+ recommended)
  • Node.js (LTS recommended) and npm
  • Google Cloud Project with Vertex AI API enabled.
  • Google OAuth 2.0 Credentials (Client ID & Secret) configured for a Web Application.

Configuration:

  1. Backend Environment (.env file):
    • Create a .env file inside the backend folder.
    • Generate secure random strings for SESSION_SECRET_KEY and SECRET_KEY (e.g., openssl rand -hex 32).
    • Add your Google Cloud AI API Key and OAuth credentials.
    • The file should look like this:
      SESSION_SECRET_KEY=YOUR_32_BYTE_HEX_SESSION_SECRET_KEY_HERE
      GOOGLE_API_KEY=YOUR_GOOGLE_AI_API_KEY_HERE
      GOOGLE_CLIENT_ID=YOUR_GOOGLE_OAUTH_CLIENT_ID_HERE
      GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_OAUTH_CLIENT_SECRET_HERE
      SECRET_KEY=YOUR_32_BYTE_HEX_JWT_SECRET_KEY_HERE
  2. Backend CORS Configuration:
    • Open backend/main.py.
    • Ensure the allow_origins list in CORSMiddleware includes your frontend URL (e.g., "http://localhost:5173").
  3. Google Cloud OAuth Configuration:
    • In your Google Cloud Console (APIs & Services -> Credentials -> Your OAuth Client ID).
    • Ensure http://localhost:5173 is under Authorized JavaScript origins.
    • Ensure http://localhost:8000/api/auth/google/callback is under Authorized redirect URIs.

Installation & Running:

You need two separate terminal windows.

Terminal 1 (Backend):

# Navigate to backend directory
cd backend

# Create venv (if needed)
# python3 -m venv venv

# Activate venv
# macOS/Linux: source venv/bin/activate
# Windows: .\\venv\\Scripts\\activate

# Install dependencies
# (Create requirements.txt first: pip freeze > requirements.txt)
pip install -r requirements.txt

# Start server
uvicorn main:app --reload

About

An interactive AI-powered training assistant that guides users through sessions with real-time feedback. Built in JavaScript for a lightweight, browser-based experience.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors