Skip to content

Yugo19/ML-Deploy

Repository files navigation

project-logo

ML-DEPLOY

FastAPI wrapper for Map Action Model deployment.

license last-commit repo-top-language repo-language-count

Developed with the software and tools below.

Streamlit Pydantic YAML OpenAI Celery Celery
Python Docker GitHub%20Actions Pytest FastAPI


Table of Contents

Overview

ML-Deploy is a versatile open-source project designed for seamless deployment and scalable management of machine learning models. Leveraging FastAPI, Celery, and Transformers, it offers robust features such as asynchronous task management, context building, and image classification. With Dockerized environments, CI/CD pipelines, and PostgreSQL integration, ML-Deploy ensures efficient ML deployment with enhanced maintainability and scalability. This projects value proposition lies in simplifying ML model deployment processes while enabling reliable and performance-driven AI applications. Developper Documentation


System Arch

The system uses fastApi endpoint to make prediction using the computer vison and the summurization using and LLM

Selection_071

How it works

Selection_067


Features

Feature Description
βš™οΈ Architecture The project utilizes FastAPI for creating APIs, Celery for asynchronous tasks, and PostgreSQL for database operations.
πŸ”© Code Quality The codebase maintains high quality with well-structured code, proper error handling, and adherence to PEP8 coding standards.
πŸ“„ Documentation Extensive documentation includes README, Dockerfile descriptions, and code comments aiding in understanding and maintaining the project.
πŸ”Œ Integrations Integrates with OpenAI for language model assistance, Redis for Celery task queuing, and GitHub Actions for automated CI/CD processes.
🧩 Modularity The codebase is modular with well-defined services for different functionalities like language model processing and image classification.
πŸ§ͺ Testing Testing is done using pytest and pytest-cov for code coverage, ensuring robustness and reliability of the project.
⚑️ Performance Efficient performance achieved through optimized code, async task processing with Celery, and Docker containers for scalability.
πŸ›‘οΈ Security Implements secure practices including handling sensitive information, maintaining Docker secrets, and CI/CD security measures.
πŸ“¦ Dependencies Key dependencies include FastAPI, Celery, Transformers, PostgreSQL, and various libraries for image processing and AI model interactions.

Repository Structure

└── ML-Deploy/
    β”œβ”€β”€ .github
    β”‚   └── workflows
    β”œβ”€β”€ Dockerfile
    β”œβ”€β”€ Dockerfile.CI
    β”œβ”€β”€ Dockerfile.Celery
    β”œβ”€β”€ LICENSE
    β”œβ”€β”€ _cd_pipeline.yaml
    β”œβ”€β”€ _ci_pipeline.yml
    β”œβ”€β”€ app
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ apis
    β”‚   β”œβ”€β”€ database.py
    β”‚   β”œβ”€β”€ main.py
    β”‚   β”œβ”€β”€ models
    β”‚   └── services
    β”œβ”€β”€ requirements.txt
    β”œβ”€β”€ test
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   └── apis
    └── vector_index
        └── chroma.sqlite3

Modules

.
File Summary
requirements.txt Lists Python package dependencies in requirements.txt for seamless project setup and reproducibility. Key libraries include fastapi, celery, transformers, and uvicorn to support ML deployment. Enhances project scalability and maintainability by managing package versions efficiently.
Dockerfile.Celery Builds a Docker image for Celery worker, leveraging Python 3.10.13, to manage asynchronous tasks in the ML-Deploy project. Inherits project dependencies from requirements.txt while ensuring a streamlined environment setup for seamless task execution.
Dockerfile Enables deploying a Python application using Uvicorn server, handling data processing requests. Utilizes Docker for portability, installs dependencies, and configures the execution environment. Dynamically serves the app on port 8001 in the container.
Dockerfile.CI Builds Python environment, installs project dependencies, and runs test coverage using pytest in the CI pipeline for ML-Deploy.
_cd_pipeline.yaml Sets up Docker services for a FastAPI app, Redis, and Celery workers with networking configurations in a micro-services environment. Enables communication between services for seamless deployment and scalability.
_ci_pipeline.yml Automates creation and configuration of a CI service within the ML-Deploy repository. Orchestrates building a Docker container for testing purposes based on the specified Dockerfile.CI. Integrates environment variables for seamless deployment.
app
File Summary
main.py Initializes FastAPI app with CORS middleware.-Connects to the database on app startup.-Gracefully disconnects from the database on app shutdown.-Includes main_routers APIs under /api1 prefix.
database.py Establishes a connection to a PostgreSQL database within the ML-Deploy repo's app module. Leveraging the databases library, it initializes a database instance with a predefined URL for subsequent data operations across the ML deployment system.
app.services.llm
File Summary
gpt_3_5_turbo.py Implements a GPT-4 assistant with chat history, user interaction, and error handling. Enables response generation based on user prompts using OpenAIs API. Facilitates chat history display and message exchange within the ML-Deploy repositorys app services architecture.
llm.py Preprocessing data for improved query results.
llm_preprocessing.py Generates a chatbot workflow utilizing OpenAI models for conversational retrieval, with document compression and retrieval. Handles document loading, splitting, and vector storage, connecting to a persistent SQLite database. Memory buffer management for conversation history. Summarizes relevant concepts for efficient chatbot interaction.
pgml_llm_preprocessing.py Implements AI chat preprocessing using pgml library with PDF data extraction, semantic search setup, and PostgreSQL integration for ML-Deploy repositorys model training pipeline.
pgml_llm.py Implements chat bot logic with context building, user input processing, and assistant response generation using AI models and a database connection.
preprocessing.py Implements a data preprocessing pipeline for a large language model, integrating text splitting, transformation, loading, embeddings, and vector storage. Executes the pipeline with model configurations and a specified tokenizer for NLP tasks within the ML-Deploy repositorys architecture.
app.services.celery
File Summary
celery_task.py Defines Celery tasks for ML predictions and contextual information retrieval using CNN and LLM models. Handles image predictions and fetches relevant context, impacts, and solutions. Enhances ML-Deploys asynchronous processing capabilities.
celery_config.py Defines Celery configuration to enable distributed task processing in the ML-Deploy repositorys architecture. Initializes a Celery object using Redis for task queuing and result storage, enhancing scalability and performance for asynchronous tasks.
app.services.cnn
File Summary
cnn_preprocess.py Enables image preprocessing for convolutional neural networks in the ML-Deploy repositorys services module. Implements transformations using the torchvision library to resize, convert, and format images for model input.
cnn.py Predicts image classification using a pre-trained VGG16 model for environmental categories. Loads weights from a specified model path, preprocesses input images, and outputs predicted class and probabilities. The CNN model aids in identifying environmental issues like pollution and waste.
cnn_model.py Refactors VGG16 model for image classification by adjusting classifier layer to predict a specified number of classes. Implements freezing parameters and loading batch normalization weights for enhanced training on ML-Deploy.
app.apis
File Summary
main_router.py Handles image prediction, contextualization, and data insertion. Utilizes FastAPI, requests, and Celery for async tasks. Fetches images, processes predictions, and stores results in the Mapapi_prediction table. Resilient to exceptions with proper error handling.
app.models
File Summary
image_model.py Defines ImageModel with image_name, sensitive_structures, and incident_id attributes.
test.apis
File Summary
test_main_router.py Verifies FastAPI endpoint functionality by simulating HTTP requests to ensure the Index route returns a 200 status code and correct JSON response.
.github.workflows
File Summary
testing.yml Enables automated testing via GitHub Actions by running test suites upon code changes. Ensures continuous integration by validating code quality, fostering robustness and stability within the ML-Deploy repository.
deploy.yml Deploys the ML model API via GitHub Actions. Orchestrates docker build and push steps, trigger-based deployment on master branch push events. Secret handling for Docker Hub credentials.

Getting Started

System Requirements:

  • Python: version x.y.z

Installation

From source

  1. Clone the ML-Deploy repository:
$ git clone https://github.com/223MapAction/ML-Deploy.git
  1. Change to the project directory:
$ cd ML-Deploy
  1. Install the dependencies:
$ pip install -r requirements.txt

Usage

From source

Run ML-Deploy using the command below:

$ uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload

Tests

Run the test suite using the command below:

$ pytest --cov=app --cov-report term-missing

Contributing

Contributions are welcome! Here are several ways you can contribute:

See our Contribution Guidelines for details on how to contribute.

Contributor Graph


License

This project is protected under the GNU GPLv3 License. For more details, refer to the LICENSE file.


Acknowledgments

  • List any resources, contributors, inspiration, etc. here.

Return


Code of Conduct

See our Code of Conduct for details on expected behavior in our community.


About

Repository for ml model deployment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published