FastAPI wrapper for Map Action Model deployment.
Developed with the software and tools below.
Table of Contents
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
The system uses fastApi endpoint to make prediction using the computer vison and the summurization using and LLM
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. |
βββ 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
.
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. |
System Requirements:
- Python:
version x.y.z
- Clone the ML-Deploy repository:
$ git clone https://github.com/223MapAction/ML-Deploy.git
- Change to the project directory:
$ cd ML-Deploy
- Install the dependencies:
$ pip install -r requirements.txt
Run ML-Deploy using the command below:
$ uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload
Run the test suite using the command below:
$ pytest --cov=app --cov-report term-missing
Contributions are welcome! Here are several ways you can contribute:
- Report Issues: Submit bugs found or log feature requests for the
ML-Deploy
project. - Submit Pull Requests: Review open PRs, and submit your own PRs.
- Join the Discussions: Share your insights, provide feedback, or ask questions.
See our Contribution Guidelines for details on how to contribute.
This project is protected under the GNU GPLv3 License. For more details, refer to the LICENSE file.
- List any resources, contributors, inspiration, etc. here.
See our Code of Conduct for details on expected behavior in our community.