ai-cfia / nachet-backend

A flask-based backend for Nachet to handle Azure endpoint and Azure storage API requests from the frontend.
MIT License
1 stars 3 forks source link

:microscope: nachet-backend 🌱

High level sequence diagram

sequenceDiagram

  title: High Level Sequence Diagram 1.0.0
  actor Client
  participant frontend
  participant backend
  participant EndpointAPI
  participant AzureStorageAPI

Client->>+frontend: getDirectoriesList()
frontend->>+backend: HTTP POST req.
backend->>+AzureStorageAPI: get_blobs()
AzureStorageAPI-->>-backend: blobListObject
backend-->>frontend: directories list res.
frontend-->>Client: display directories
Client->>frontend: handleInference()
frontend->>backend: HTTP POST req.
backend->>+AzureStorageAPI: upload_image(image)
AzureStorageAPI-->>-backend: imageBlobObject
backend->>+EndpointAPI: get_inference_result(image)
EndpointAPI-->>-backend: inference res.
backend->>backend: process inf. result
backend-->>frontend: inference res.
frontend-->>-Client: display inference res.
backend->>+AzureStorageAPI: (async) upload_inference_result(json)

Details


RUNNING NACHET-BACKEND FROM DEVCONTAINER

When developping you first need to install the packages required.

This command must be run the first time you want to run the backend on your computer, but also every time you update the requirements.txt file and every time the datastore repo is updated

pip install -r requirements.txt

Then, you can run the backend while in the devcontainer by using this command:

hypercorn -b :8080 app:app

RUNNING NACHET-BACKEND AS A DOCKER CONTAINER

If you want to run the program as a Docker container (e.g., for production), use:

docker build -t nachet-backend .
docker run -p 8080:8080 -e PORT=8080 -v $(pwd):/app nachet-backend

RUNNING NACHET-BACKEND WITH THE FRONTEND IN DOCKER

If you want to run the frontend and backend together in Docker, use:

docker-compose up --build

You can then visit the web client at http://localhost:80. The backend will be build from the Dockerfile enabling preview of local changes and the frontend will be pulled from our Github registry.

TESTING NACHET-BACKEND

To test the program, use this command:

python -m unittest discover -s tests

ENVIRONMENT VARIABLES

Start by making a copy of .env.template and renaming it .env. For the backend to function, you will need to add the missing values:

DEPRECATED


DEPLOYING NACHET

If you need help deploying Nachet for your own needs, please contact us at cfia.ai-ia.acia@inspection.gc.ca.