This repository contains a Jupyter notebook demonstrating how to integrate the Bria attribution service providing full legal indemnity when hosting Bria's models on your cloud / environment.
There are 2 parts to this integration:
- Installing the Bria attribution model for calculating embeddings (irreversible vectors) of your generated images.
- API Integration for sharing the embeddings with Bria.
The code_example.ipynb notebook provides a complete workflow for:
- Setting up and running the BRIA attribution model using Docker and Triton inference server
- Generating image embeddings using the BRIA model
- Sending attribution API requests with the generated embeddings
Before running this example, ensure you have the following installed:
- Docker
- Python 3 with the packages (pip install -r ./requirements.txt --use-deprecated=legacy-resolver)
- NVIDIA GPU with CUDA support (recommended)
You'll need to configure your BRIA API token to access the model repository and attribution service. Replace the placeholder values in the notebook:
api_token = '<API_TOKEN>'Required substitutions:
<API_TOKEN>: Your BRIA API token for accessing the attribution service
The notebook will automatically:
- Fetch ECR credentials using your API token from the BRIA attribution service
- Login to Amazon ECR using the fetched credentials
- Pull the BRIA attribution model Docker image
- Start the Triton inference server with the model
The model will be available on:
- Port 8000: HTTP endpoint
- Port 8001: Metrics endpoint
- Port 8002: GRPC endpoint
-
BRIA Embeddings URL:
url = '<BRIA_EMBEDDINGS_URL>:8000'
Replace
<BRIA_EMBEDDINGS_URL>with your server's IP address or hostname (localhost if running on the same machine). -
Image Path:
image_path = '<IMAGE_PATH>'
Replace
<IMAGE_PATH>with the path to your input image file. -
API Token (in attribution request):
api_token = '<API_TOKEN>'
Replace
<API_TOKEN>with your BRIA API token.
Execute the first cell to:
- Configure your API token
- Fetch ECR credentials from the BRIA attribution service
- Login to ECR using the fetched credentials
- Pull and run the BRIA attribution model container
Run the installation cell to import required libraries:
requestsfor API callstritonclient.httpfor Triton inferencePILfor image processingembeddermodule (BRIAEmbedder class)
Execute the inference request cell to:
- Connect to the Triton server
- Load and process your image
- Generate embeddings using the BRIA model
Run the attribution API cell to:
- Create a unique embedding ID
- Send the embeddings to the attribution service
- Handle the API response
The notebook uses these default parameters:
- Model Version: 2.3
- Model Name: 'replace-backgroud'
- Agent: Your API token
The attribution API expects the following JSON structure:
{
"embeddings_base64": "<base64_encoded_embeddings>",
"embeddings_uid": "<unique_identifier>",
"model_version": 2.3,
"agent": "<API_TOKEN>",
"model_name": "replace-backgroud"
}