Skip to content
/ MSAPI Public

MSAPI (Melanoma Segmentation API) is a FastAPI-based REST API that communicates with segmentation and classification models for melanoma detection in dermoscopic images.

Notifications You must be signed in to change notification settings

fedemelo/MSAPI

Repository files navigation

Melanoma Segmentation API

Quality Gate Status Code style: black Imports: isort


Melanoma Segmentation API (MSAPI) is a FastAPI-based REST API that communicates with segmentation and classification models for melanoma detection in dermoscopic images.

It is designed to be consumed by the Melanoma Segmentation Web Application (MSWA).

Quick Reference

The official documentation for the API was built automatically by Swagger and is available at http://localhost:8000 once the server is running.

However, the following table provides a quick reference for the most important endpoints available.

Request Type Endpoint Path Description
POST v1.0/doctors Registers a new user with fields: name, email, and password. Ensures email is unique.
POST v1.0/doctors/login Authenticates a user using email and password with the OAuth 2.0 protocol.
GET/PUT v1.0/doctors/<email> Retrieves (GET) or updates (PUT) doctor profile information.
GET v1.0/patients/<cedula> Retrieves the patient information, including all images uploaded for a patient and their segmentation masks.
POST v1.0/patients Registers a new patient with fields: name, cédula, and doctor email. Ensures cédula is unique.
POST v1.0/images Allows uploading a named image to a patient with their cédula.
POST v1.0/images/process [PENDING] Processes the uploaded image and returns the segmentation mask by communicating with the model.

Local Setup

The project must be run using Python 3.11.3.

  1. Clone the repository and navigate to the project directory:

    git clone https://github.com/fedemelo/MSAPI
    cd msapi

Dependencies

  1. Create a virtual environment

    python3.11 -m venv venv
  2. Activate the virtual environment

    Unix:

    source venv/bin/activate

    Windows:

    venv\Scripts\activate.bat
  3. Install dependencies

    pip install -r requirements.txt

Warning

Windows users

Note that the uvloop package is not compatible with Windows. If it is present in the requirements.txt file, it must be manually removed before installing the dependencies. Removing it will not affect API functionality.

  1. Install pre-commit hooks

    pre-commit install

    This will ensure that the code is formatted, linted, and tested before each commit. See Code Quality for more information.

Database

  1. Create the database or restore a backup

    Either create a new database or restore a backup:

    • To create new database, run the following command:

      psql -U postgres -c "CREATE DATABASE melanoma_segmentation_db"

      Then, run the application. The application will create the necessary tables.

    • To restore a backup, run the corresponding script.

      Unix:

      sh db/restore-db-backup.sh

      Windows:

      db\restore-db-backup.bat

Note

There's also a script to save a backup of the database, db/save-db-backup, which saves the current state of the database into the db/backups directory.

Run the Server

  1. Run the server. In the root of the project, run the following command:

    python -m run

    The server will be running on http://localhost:8002

Code Quality

Before each commit, the code is automatically formatted, linted, and tested using a pre-commit hook. After each push, the code is scanned by SonarCloud.

Access SonarCloud here.

Formatting, Linting, and Testing

The code is formatted using Black and isort, linted with Flake8, and tested with Pytest.

A pre-commit hook takes care of formatting, linting, and testing the code before each commit. It must be installed by running the following command:

pre-commit install

Manual Formatting, Linting, and Testing

Should the pre-commit hook fail, the code can be manually formatted, linted, and tested.

To manually format the code:

isort . && black .

To lint the code:

flake8 .

API Design

The API is structured based on the design illustrated in the UML class diagram below:

MSAPI Class Diagram

Important Considerations

While the UML diagram provides a high-level overview of the API design, there are specific details about how deletions are handled that are not depicted in the diagram. These are outlined as follows:

  • Doctor Deletion:
    The API restricts the deletion of a doctor if they have patients associated with them. Any attempt to delete such a doctor will be rejected.

  • Patient Deletion:
    The API permits the deletion of a patient. When a patient is deleted, all associated images and predictions are automatically removed as part of the deletion process.

About

MSAPI (Melanoma Segmentation API) is a FastAPI-based REST API that communicates with segmentation and classification models for melanoma detection in dermoscopic images.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published