In this example we will create an endpoint to upload images to a bucket and then run them through an image classification model using ImageAI.

Our application will:

  1. Load our model from local storage in a dependency ensuring the model is ready before we receive image uploads, and it can be shared across requests.
  2. Expose an endpoint that allows users to upload images
  3. When our endpoint receives an image, it will upload the image to a bucket (GCS or S3)
  4. When the image is uploaded it will trigger a notification to our queue (GCP Pub/Sub or AWS SQS)
  5. Our consumer will receive this notification and run the image through an image classification model using ImageAI
  6. The results of the image classification will be stored in a data warehouse (BigQuery) or DuckDB)
  7. The data warehouse will be exposed by another endpoint

If all goes well, you should have a working image classification app like this:

Before completing the example ensure you have installed BuildFlow with all extra dependencies.

  • GCP

  • AWS

  • Local

To run this example on resources created on GCP use this github repo.

In order to run this code you will need to have a GCP project created that you have access to.

Follow the Google Cloud Walkthrough to create a new one if you need to.


Clone the GitHub Repo

git clone 
cd buildflow-gcp-image-classification

Install your requirements

    pip install -r requirements.txt

Create a .env file

Rename the template.env to .env and update all variables


Create your resources

Create all the resources that are required for your system.

    buildflow apply

Make sure you have logged in with GCP with: gcloud auth login --update-adc

This will output every primitive that will be created, and ask you to confirm before creating them:

    Primitives to create:
    ├── GCSBucket
    │   └── gcs://<GCP_PROJECT_ID>-image-classification
    ├── BigQueryDataset
    │   └── <GCP_PROJECT_ID>.buildflow_image_classification_walkthrough
    ├── BigQueryTable
    │   └── <GCP_PROJECT_ID>.buildflow_image_classification_walkthrough.image_classification
    ├── GCSFileChangeStream
    │   └── <GCP_PROJECT_ID>-image-classification.<GCP_PROJECT_ID>-image-classification_topic
    ├── GCPPubSubSubscription
    │   └── <GCP_PROJECT_ID>/<GCP_PROJECT_ID>-image-classification_subscription
    └── GCPPubSubTopic
        └── <GCP_PROJECT_ID>/<GCP_PROJECT_ID>-image-classification_topic

    Would you like to apply these changes?
    Enter "y (yes)" to confirm, "n (no) to reject":

Run your project

Run your project with:

    buildflow run

Once running you can visit http://localhost:8000 to see and begin uploading images!

We provide a picture of Caleb’s dog in the repo to help get you started!



What's next?

Now that you have a working image classification app, you can start to customize it to your needs. Such as adding google auth for user authentication or a postgres database for permanent storage. Or even hosting your own model on a private bucket.