Skip to main content

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

# Método recomendado de instalación:
pip install abril[all]

# Si encuentras problemas, puedes instalar las dependencias manualmente:
pip install torch>=1.7.1 pillow>=7.1.2 numpy>=1.18.5
pip install git+https://github.com/openai/CLIP.git
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


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.8.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abril-0.1.8-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file abril-0.1.8.tar.gz.

File metadata

  • Download URL: abril-0.1.8.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.13

File hashes

Hashes for abril-0.1.8.tar.gz
Algorithm Hash digest
SHA256 f4e02769747867c3b128dac3ca1c46c70312fbf1467c7d0e5513b6c7878b7692
MD5 8d1f09ae00c5f599ce69226a5c62bdf9
BLAKE2b-256 cd60bd86e8630175dea2a297f6c8b9fcd49f4eab4eb64899824c53af14ebe7f0

See more details on using hashes here.

File details

Details for the file abril-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: abril-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.13

File hashes

Hashes for abril-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1602446860d1badaa5e188f9a0229face4595c27597e7662786af9eae4f3bad0
MD5 0c7646d0910adaefb3a24472b9b0cae7
BLAKE2b-256 4c1120e64e7bda093359308b15b237afa833fc6d5a1ec9801e20c5ca5f0ab7e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page