Skip to content

Image Classification Web API using FastAPI and PyTorch

License

Notifications You must be signed in to change notification settings

SkxPhan/ImageVisionAPI

Repository files navigation

ImageVisionAPI

Image Classification Web Application with FastAPI and Gradio

License Python Versions CI Docker Image Version

This project demonstrates a complete pipeline for a image classification system using Convolutional Neural Networks (CNNs), FastAPI, Gradio, and Docker. The project includes user authentication, image upload, classification, and history retrieval, with a focus on continuous integration and deployment.

Table of Contents

Introduction

This project provides a comprehensive example of how to build a machine learning application with a REST API for model inference and a user-friendly interface for interacting with the model. It includes user authentication, image upload functionality, and a history of past classifications.

Features

  • CNN Model: Image classification using a Convolutional Neural Network built with PyTorch.
  • FastAPI: High-performance API backend.
  • Gradio: User-friendly interface for image upload and classification. (TODO)
  • PostgreSQL: Relational database for storing user data and classification history.
  • User Authentication: Secure JWT-based authentication.
  • CI/CD: Continuous integration and deployment using GitHub Actions.
  • Docker: Containerized deployment for easy setup and scaling.

Technologies

  • Python
  • PyTorch
  • FastAPI
  • Gradio
  • SQLAlchemy
  • PostgreSQL
  • JWT
  • Docker
  • GitHub Actions
  • Poetry

Setup

Prerequisites

  • Docker
  • Docker Compose
  • Poetry
  • Python 3.10+

Clone the repository

git clone https://github.com/username/repository.git
cd repository

Install dependencies

poetry install

Setup environment variables

Create a .env file in the root directory. See env_example.txt for more details.

Run the application

docker-compose up --build

The FastAPI application will be available at http://localhost:8000.

Usage

FastAPI Endpoints

  • Register: POST /api/v1/auth/register
  • Login: POST /api/v1/auth/login
  • Logout: POST /api/v1/auth/logout
  • Classify Image: POST /api/v1/ml/predict
  • Get User Info: GET /api/v1/users/me
  • Get History: GET /api/v1/users/me/history

API Documentation

FastAPI provides interactive API documentation (Swagger) at http://localhost:8000/docs and http://localhost:8000/redoc.

CI/CD

The project includes a GitHub Actions workflow for continuous integration and deployment and defined in .github/workflows.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

Image Classification Web API using FastAPI and PyTorch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published