This repository contains an internal service that provides AI capabilities to the PersonalMediaVault daemon.
The internal service is written in Python, using the Flask web framework.
The service provides the following capabilities / models:
- CLIP: An open source model developed by OpenAI that connects text with images, turning both into vectors of the same dimension. This enables semantic search by ordering the available images by vector distance (shortest distance means a greater relationship in meaning between the text and the image). PersonalMediaVault makes uses of this model, in combination with a vector database, in order to enable semantic search of images.
- Python (Version 3)
First, create and activate the virtual environment:
./virtual-env.shThen, install the dependencies:
pip install -r requirements.txtIn order to run the project, you can use the following script:
./run.shThis will run the Flask development server in the default port (usually 5000)
In order to build the wheel file, run:
./build-production.shThe wheel file will be placed in the dist folder.
You can then install the wheel file in another machine:
pip install pmv_ai_service-1.0.0-py3-none-any.whlOnce installed, you can use a production WSGI server, for example, Waitress in order to run the service in production:
waitress-serve 'pmv_ai_service.app:app'
You can find the docker images for this project available in Docker Hub:
We offer a default image for CPU and NVIDIA GPUs (asanrom/pmv-ai-service), along with an image for AMD GPUs using ROCm (asanrom/pmv-ai-service-rocm).
To pull the image type:
docker pull pmv-ai-service
When running on a container, the service will listen to the 8080 port by default. You can change this by overriding the command option of the container. Check the waitress-serve documentation for more options.
You can configure the service using environment variables passed to the container:
| Variable name | Description |
|---|---|
LOGLEVEL |
Log level. Can be ERROR, WARNING, INFO or DEBUG |
API_AUTHORIZATION |
Expected value for the authorization header when calling the API. Make sure to use a strong, random string to protect the service. |
CLIP_MODEL_NAME |
Name of the CLIP model to use. Default: ViT-B/32. Available models: RN50, RN101, RN50x4, RN50x16, RN50x64, ViT-B/32, ViT-B/16, ViT-L/14 and ViT-L/14@336px |
# Example compose file
services:
pmv_ai_service:
hostname: pmv_ai_service
ports:
- '8080:8080'
image: 'asanrom/pmv-ai-service'
build:
context: .
restart: unless-stopped
volumes:
- ./.data:/home/app/.data
command: --port=8080 pmv_ai_service.app:app
environment:
- LOGLEVEL=${LOGLEVEL:-INFO}
- API_AUTHORIZATION=${API_AUTHORIZATION:-}
- CLIP_MODEL_NAME=${CLIP_MODEL_NAME:-}This project is under the MIT License.