A library for comparing text and images using CLIP
Project description
Abril - Text-Image Comparison using CLIP
Abril is a Python library that makes it easy to compare text and images using OpenAI's CLIP model. It provides a simple interface for calculating similarity scores between text descriptions and images.
Installation
pip install abril
# If you encounter any issues, you can install dependencies manually:
pip install torch>=1.7.1 pillow>=7.1.2 numpy>=1.18.5
pip install git+https://github.com/openai/CLIP.git@v0.1.5
pip install abril
Usage
from abril import ClipComparer
from PIL import Image
# Initialize the comparer
comparer = ClipComparer()
# Compare a single text with an image
score = comparer.compare_text_with_image(
"a photo of a dog",
"path/to/image.jpg"
)
print(f"Similarity score: {score}")
# Find the best matching text for an image
texts = [
"a photo of a dog",
"a photo of a cat",
"a photo of a car"
]
best_text, score = comparer.find_best_match(texts, "path/to/image.jpg")
print(f"Best match: {best_text} (score: {score})")
Features
- Easy-to-use interface for text-image comparison
- Support for both single and multiple text comparisons
- Uses CLIP's ViT-B/32 model by default (can be changed)
- Automatically uses GPU if available for faster processing
- Handles both file paths and PIL Images flexibly
- Normalizes features for better comparison
- Returns scores between 0 and 1 for easy interpretation
- Built on OpenAI's CLIP model
- GPU acceleration when available
Requirements
- Python ≥ 3.7
- PyTorch ≥ 1.7.1
- Other dependencies are handled automatically during installation
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
abril-0.1.5.tar.gz
(4.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
abril-0.1.5-py3-none-any.whl
(4.7 kB
view details)
File details
Details for the file abril-0.1.5.tar.gz.
File metadata
- Download URL: abril-0.1.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b590ea407abad20849e33f1aa443e68573d705ed83d8f3c49785b7666d642b65
|
|
| MD5 |
7b1bf2c94ebdab15d8044a7c20e188b7
|
|
| BLAKE2b-256 |
75195ca7e027fd3eb10428716106b9f3a1599ab74241700b2248939dbf85663c
|
File details
Details for the file abril-0.1.5-py3-none-any.whl.
File metadata
- Download URL: abril-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae55bf4e5d2ce2cb1de2e0988cdc4501ad6315ff2100d0fb25f7e302c19390c
|
|
| MD5 |
62c33b582521f3300c70f2f1477dd4c3
|
|
| BLAKE2b-256 |
bb643a3a09735cbfb95deab3bfb14a0c40690c387f7255a51244f718d3e8a305
|