Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ms. Potts - AI-powered Nutrition Assistant


Build Status Python Version License Made with FastAPI Gemini API Gradio UI Dockerized CI/CD Linted with Ruff Pre-commit Hooks MLflow Tracking GCP Cloud Run

Ms. Potts is an AI-powered nutrition chatbot that provides meal recommendations, dietary advice, and meal logging, personalized based on user profile information. This project follows MLOps best practices with comprehensive monitoring, experiment tracking, and configuration management.

DEMO:

GCP APP LINK

Step-1 User Profile Creation

User Peofile

Step-2 User query for Nutrition Advice

Nutrtion Advise Response

Features

  • Retrieval-Augmented Generation (RAG) Pipeline
  • Intent Classification
  • Personalized Meal Planning
  • Meal Logging
  • Gemini API Integration
  • MLOps Best Practices (Phase 2)

Tech Stack

  • FastAPI (Backend API)
  • Gradio (Frontend UI)
  • Sentence-Transformers
  • Google Gemini API
  • Docker Containerization with Docker Compose
  • MLflow Experiment Tracking
  • Hydra Configuration Management
  • Enhanced Logging and Monitoring

Phase 2 MLOps Enhancements

1. Containerization with Docker

The project has been containerized using separate Dockerfiles for frontend and backend, orchestrated with Docker Compose:

# Build and run with Docker Compose
docker-compose up --build

# Access the frontend at http://localhost:7860
# Access the backend at http://localhost:8080

The Dockerfiles include:

  • Python 3.10 base image
  • All required dependencies
  • Proper directory structure
  • Environment variable configuration
  • Separate entry points for frontend and backend

2. Monitoring & Debugging

πŸ“Š Monitoring & Debugging Documentation For setup, examples, and troubleshooting guides, click here.

Comprehensive monitoring and debugging tools have been integrated:

# Initialize monitoring
from utils.monitoring import ModelMonitor
monitor = ModelMonitor(metrics_dir="./metrics")
monitor.start_monitoring(interval=5)

# Log model metrics
monitor.log_model_metrics({
    "latency_ms": latency_ms,
    "tokens_generated": tokens_generated
})

# Initialize debugging
from utils.debugging import DebugTracer, debug_value
tracer = DebugTracer(output_dir="./debug_traces")

# Trace function calls
@tracer.trace_function
def process_query(query):
    # Function code
    return result

Monitoring metrics include:

  • System resources (CPU, memory, disk usage)
  • Model performance (latency, token count)
  • Application metrics (request processing time, endpoint usage)

3. Profiling & Optimization

For Profiling details and Results, click here.

Profiling tools have been added to identify performance bottlenecks:

# Initialize profilers
from utils.profiling import CodeProfiler, MLProfiler
code_profiler = CodeProfiler(output_dir="./profiling_results")
ml_profiler = MLProfiler(output_dir="./ml_profiling_results")

# Profile functions
@code_profiler.profile_function
def embed_query(query):
    # Function code
    return embedding

# Profile specific code blocks
with code_profiler.profile_block("similarity_search"):
    similarities = calculate_similarities()

Profiling results are saved to:

  • ./profiling_results/ for Python code profiling
  • ./ml_profiling_results/ for ML model profiling

4. Experiment Tracking with MLflow

For Profiling details and Results, click here.

MLflow has been integrated for experiment tracking:

# Start the MLflow UI
mlflow ui

# Access the UI at http://localhost:5000

The application automatically logs:

  • Model parameters (embedding model, similarity threshold)
  • Performance metrics (retrieval time, response time)
  • Query and response data
  • Model artifacts

5. Enhanced Logging

For Logging Details, click here. Rich, structured logging has been implemented:

# Initialize enhanced logger
from utils.enhanced_logging import EnhancedLogger, log_with_context
enhanced_logger = EnhancedLogger(
    name="ms_potts",
    level="info",
    log_dir="./logs",
    console_output=True,
    file_output=True,
    json_output=True,
    rich_formatting=True
)
logger = enhanced_logger.get_logger()

# Context-aware logging
log_with_context(
    logger,
    "info",
    "Processing query request",
    request_id=request_id,
    query=query
)

Logs are stored in ./logs/ with detailed context information.

6. Configuration Management with Hydra

For Configuration Managment, click here. Hydra has been integrated for hierarchical configuration management:

# Run with default (production) configuration
python -m src.ms_potts.main

# Run with development configuration
python -m src.ms_potts.main +mode=development

# Override specific parameters
python -m src.ms_potts.main model.batch_size=64 app.port=9000

Configuration files are organized in the conf/ directory:

  • config.yaml: Main configuration
  • development.yaml: Development environment overrides
  • production.yaml: Production environment overrides
  • testing.yaml: Testing environment overrides

Setup Instructions

Prerequisites

  • Python 3.10+
  • Docker and Docker Compose (for containerized deployment)

Local Installation

  1. Clone this repository:
git clone https://github.com/Vedant-1012/ms-potts-mlops.git
cd ms-potts-mlops
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file with your Gemini API Key:
GEMINI_API_KEY=your_api_key_here
  1. Run the application:
python src/ms_potts/main.py  # Backend
python src/ms_potts/interface.py  # Frontend
  1. Access the frontend at http://localhost:7860 and the API at http://localhost:8080

Docker Deployment

  1. Build and run with Docker Compose:
docker-compose up --build
  1. Access the frontend at http://localhost:7860 and the API at http://localhost:8080

Project Organization

    β”œβ”€β”€ LICENSE
    β”œβ”€β”€ Makefile           <- Makefile with commands like `make data` or `make train`
    β”œβ”€β”€ README.md          <- The top-level README for developers using this project.
    β”œβ”€β”€ data
    β”‚   β”œβ”€β”€ external       <- Data from third party sources.
    β”‚   β”œβ”€β”€ interim        <- Intermediate data that has been transformed.
    β”‚   β”œβ”€β”€ processed      <- The final, canonical data sets for modeling.
    β”‚   └── raw            <- The original, immutable data dump.
    β”‚
    β”œβ”€β”€ docs               <- A default Sphinx project; see sphinx-doc.org for details
    β”‚
    β”œβ”€β”€ models             <- Trained and serialized models, model predictions, or model summaries
    β”‚
    β”œβ”€β”€ notebooks          <- Jupyter notebooks. Naming convention is a number (for ordering),
    β”‚                         the creator's initials, and a short `-` delimited description, e.g.
    β”‚                         `1.0-jqp-initial-data-exploration`.
    β”‚
    β”œβ”€β”€ references         <- Data dictionaries, manuals, and all other explanatory materials.
    β”‚
    β”œβ”€β”€ reports            <- Generated analysis as HTML, PDF, LaTeX, etc.
    β”‚   └── figures        <- Generated graphics and figures to be used in reporting
    β”‚
    β”œβ”€β”€ requirements.txt   <- The requirements file for reproducing the analysis environment, e.g.
    β”‚                         generated with `pip freeze > requirements.txt`
    β”‚
    β”œβ”€β”€ setup.py           <- makes project pip installable (pip install -e .) so src can be imported
    β”œβ”€β”€ src                <- Source code for use in this project.
    β”‚   β”œβ”€β”€ __init__.py    <- Makes src a Python module
    β”‚   β”‚
    β”‚   β”œβ”€β”€ data           <- Scripts to download or generate data
    β”‚   β”‚   └── make_dataset.py
    β”‚   β”‚
    β”‚   β”œβ”€β”€ features       <- Scripts to turn raw data into features for modeling
    β”‚   β”‚   └── build_features.py
    β”‚   β”‚
    β”‚   β”œβ”€β”€ models         <- Scripts to train models and then use trained models to make
    β”‚   β”‚   β”‚                 predictions
    β”‚   β”‚   β”œβ”€β”€ predict_model.py
    β”‚   β”‚   └── train_model.py
    β”‚   β”‚
    β”‚   └── visualization  <- Scripts to create exploratory and results oriented visualizations
    β”‚       └── visualize.py
    β”‚
    β”œβ”€β”€ docker-compose.yml <- Docker Compose configuration
    β”œβ”€β”€ Dockerfile.backend <- Dockerfile for the backend service
    β”œβ”€β”€ Dockerfile.frontend <- Dockerfile for the frontend service
    β”‚
    β”œβ”€β”€ conf               <- Hydra configuration files
    β”‚   β”œβ”€β”€ config.yaml    <- Main configuration
    β”‚   β”œβ”€β”€ development.yaml <- Development environment overrides
    β”‚   β”œβ”€β”€ production.yaml <- Production environment overrides
    β”‚   └── testing.yaml   <- Testing environment overrides
    β”‚
    β”œβ”€β”€ mlruns            <- MLflow experiment tracking data
    β”‚
    β”œβ”€β”€ logs              <- Application logs
    β”‚
    β”œβ”€β”€ metrics           <- Monitoring metrics
    β”‚
    β”œβ”€β”€ profiling_results <- Code profiling results
    β”‚
    └── tox.ini            <- tox file with settings for running tox; see tox.readthedocs.io

MLOps Best Practices

This project follows these MLOps best practices:

  1. Containerization: Docker and Docker Compose for consistent deployment
  2. Monitoring: Tracking system and application metrics
  3. Debugging: Tracing and value inspection tools
  4. Profiling: Performance analysis for Python and ML code
  5. Experiment Tracking: MLflow for tracking parameters, metrics, and artifacts
  6. Enhanced Logging: Rich, structured logging with context
  7. Configuration Management: Hydra for hierarchical configuration

Team

License

MIT License


Project based on the cookiecutter data science project template. #cookiecutterdatascience

Releases

Packages

Used by

Contributors

Languages