Skip to main content

A package for CLIP-based image and text processing.

Project description

CLIPCraft

CLIPCraft is a package written in Python for use by Data Scientists/Analysts working with image-to-text and text-to-image implementations.

More specifically, CLIPCraft contains user-friendly functions that are incredibly simple and easy to use, providing a simple and convenient interface for text and image projects.

Features:

Embedding Extraction: Extract embeddings for images and texts using CLIP.
Image-to-Text: Generate textual descriptions (captions) for given images using CLIP. Currently, you must provide your own list of captions.
Text-to-Image from Embeddings: Generate visual representations from embeddings for given texts using CLIP.

Installation

pip install clipcraft

Usage

CLIPCraft offers 4 functions for users to interact with;

createImageEmbeddings(input_urls) This function creates image embeddings from a file containing URLs, where input_urls is a string of a filename or a list of strings of filenames. It returns a list of tuples, where the 0th value is the image URL, and the 1st value is the resulting embedding.

createTextEmbeddings(input_text) This function creates text embeddings from a user-input string of text or list of strings of text. It returns a list of tuples, where the 0th value is the raw text, and the 1st value is the resulting embedding.

KNNSearchImage(text_embeddings, image_embeddings) This function will find the nearest 10 similar images from given text embedding(s) list using K-Nearest-Neighbors. It is designed for use by providing the list returned from createTextEmbeddings. text_embeddings should be the return value of createTextEmbeddings, while image_embeddings should be the return value for createImageEmbeddings.

KNNSearchText(text_embeddings, image_urls) This function will find the most similar caption to a given image. It is designed for use by providing the list returned from createTextEmbeddings. text_embeddings should be the return value of createTextEmbeddings, while image_urls should be a single URL or a list of URLs.

Example

import clipcraft as cc

file_urls = ["first_100_rows.json.gz"]

image_embeds = cc.createImageEmbeddings(file_urls)

text_embed_list = ["a man in a green jacket and a basketball player in a white shirt",  "Grandma with makeup", "Football player"]

text_embeds = cc.createTextEmbeddings(text_embed_list)

cc.KNNSearchImage(text_embeds, image_embeds)

cc.KNNSearchText(textembeds, ["https://www.outkick.com/wp-content/uploads/Nowell-Thomas.jpg"])

Note the arguments taken by the KNN functions are the return values of the previous external functions.

The output of KNNSearchImage will be 5 images with the closest euclidean distance in ascending order; that is, the closest related image being output first.
The output of KNNSearchText will be a caption of the image based on the lowest euclidean distance between your list of input captions and the input image.

Requirements

The requirements for the package can be found in requirements.txt. However, note that these dependencies will be automatically installed when invoking the pip command.

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

clipcraft-1.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

clipcraft-1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file clipcraft-1.1.tar.gz.

File metadata

  • Download URL: clipcraft-1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for clipcraft-1.1.tar.gz
Algorithm Hash digest
SHA256 d6e45d1602acd8a7c0d06f78057e8067427c60e500177e429ff690c127f77f74
MD5 f28881c2163c7f2dba20807c02b70165
BLAKE2b-256 772e624525897fe21b69a1a184b7ac8d696a2f55ca750d55fed890bcba456fa5

See more details on using hashes here.

File details

Details for the file clipcraft-1.1-py3-none-any.whl.

File metadata

  • Download URL: clipcraft-1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for clipcraft-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c2d9ce493bf3bc513fa06d9fce9d27b1d22b0646fbd5decd3645026dded409a
MD5 53618c16bc5295e508bb5630240d2d16
BLAKE2b-256 de30c84e52005ad9e42d47a4970553d0f9da33d5a4d1cd1fe03f764a454d466a

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