Skip to main content

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, output_type) 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, and output_type is the type of output desired for the embeddings; "list" or "file". 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, output_type) This function creates text embeddings from a user-input string of text or list of strings of text. output_type is the type of output desired for the embeddings; "list" or "file". 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, display_amount) 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. display_amount is the amount of related images to be returned.

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 = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Orange_tabby_cat_sitting_on_fallen_leaves-Hisashi-01A.jpg/800px-Orange_tabby_cat_sitting_on_fallen_leaves-Hisashi-01A.jpg"

image_embeds = cc.createImageEmbeddings(file_urls, "list")

text_embed_list = ["a picture of a cat"]

text_embeds = cc.createTextEmbeddings(text_embed_list, "list")

cc.KNNSearchImage(text_embeds, image_embeds, 10)

cc.KNNSearchText(text_embeds, ["https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Orange_tabby_cat_sitting_on_fallen_leaves-Hisashi-01A.jpg/800px-Orange_tabby_cat_sitting_on_fallen_leaves-Hisashi-01A.jpg"])

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

The output of KNNSearchImage will be your specified amount 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

To run the functions from this package, you must install PyTorch, as the Hugging Face Transformers library is built on top of it. Instructions to do so can be found here: https://pytorch.org/get-started/locally/

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.

Release files for clipcraft 1.4.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clipcraft 1.4.6
File Size Uploaded
clipcraft-1.4.6.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for clipcraft 1.4.6
File Interpreter ABI Platform
clipcraft-1.4.6-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / clipcraft-1.4.6.tar.gz

Download URL clipcraft-1.4.6.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a3ce7b98a6d31e25d6be73a8aae73d4b02b1a5a24db2bba884c75247b520fb9f
BLAKE2b-256 checksum
How to use checksums
f18696cf82333e29559b6235ae621adb54d64adfb436a7cfe3feb65756696d8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / clipcraft-1.4.6-py3-none-any.whl

Download URL clipcraft-1.4.6-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5677b24a64b7226f891dad49dcd0ea578380588207d0559869d7b60220d9b85e
BLAKE2b-256 checksum
How to use checksums
a2459400b822ced55cf78335dd2faf0473d2c35e60a6245459bbd73927a96cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.4.6 This release

2 release files

1.4.5

1 release file

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

3 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page