clip-interrogator
Want to figure out what a good prompt might be to create new images like an existing one? The CLIP Interrogator is here to get you answers!
Run it!
🆕 Now available as a Stable Diffusion Web UI Extension! 🆕
Run Version 2 on Colab, HuggingFace, and Replicate!
Version 1 still available in Colab for comparing different CLIP models
About
The CLIP Interrogator is a prompt engineering tool that combines OpenAI's CLIP and Salesforce's BLIP to optimize text prompts to match a given image. Use the resulting prompts with text-to-image models like Stable Diffusion on DreamStudio to create cool art!
Using as a library
Create and activate a Python virtual environment
python3 -m venv ci_env
(for linux ) source ci_env/bin/activate
(for windows) .\ci_env\Scripts\activate
Install with PIP
# install torch with GPU support for example:
pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu117
# install clip-interrogator
pip install clip-interrogator==0.5.5
You can then use it in your script
from PIL import Image
from clip_interrogator import Config, Interrogator
image = Image.open(image_path).convert('RGB')
ci = Interrogator(Config(clip_model_name="ViT-L-14/openai"))
print(ci.interrogate(image))
CLIP Interrogator uses OpenCLIP which supports many different pretrained CLIP models. For the best prompts for
Stable Diffusion 1.X use ViT-L-14/openai for clip_model_name. For Stable Diffusion 2.0 use ViT-H-14/laion2b_s32b_b79k
Configuration
The Config object lets you configure CLIP Interrogator's processing.
clip_model_name: which of the OpenCLIP pretrained CLIP models to usecache_path: path where to save precomputed text embeddingsdownload_cache: when True will download the precomputed embeddings from huggingfacechunk_size: batch size for CLIP, use smaller for lower VRAMquiet: when True no progress bars or text output will be displayed
On systems with low VRAM you can call config.apply_low_vram_defaults() to reduce the amount of VRAM needed (at the cost of some speed and quality). The default settings use about 6.3GB of VRAM and the low VRAM settings use about 2.7GB.
See the run_cli.py and run_gradio.py for more examples on using Config and Interrogator classes.
Ranking against your own list of terms
from clip_interrogator import Config, Interrogator, LabelTable, load_list
from PIL import Image
ci = Interrogator(Config(blip_model_type=None))
image = Image.open(image_path).convert('RGB')
table = LabelTable(load_list('terms.txt'), 'terms', ci)
best_match = table.rank(ci.image_to_features(image), top_count=1)[0]
print(best_match)
Metadata
Release files for clip-interrogator 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| clip-interrogator-0.6.0.tar.gz | 788.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clip_interrogator-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.6 MB
Release files / clip-interrogator-0.6.0.tar.gz
| Download URL | clip-interrogator-0.6.0.tar.gz |
|---|---|
| Size | 788.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7942372fe9b96181881f7083e3179de746e59b0e3c4199fb3e3e19bef421693
|
|
BLAKE2b-256 checksum How to use checksums |
23d12f0f61c5cbaea3d1480f2eb2709f89d64d62976e9634e7eeaac2e2c03ba2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / clip_interrogator-0.6.0-py3-none-any.whl
| Download URL | clip_interrogator-0.6.0-py3-none-any.whl |
|---|---|
| Size | 787.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd7c6bf9db170f005b4179e943fc1658aa0f8eebcc75ab3428b0a992aaeabd1c
|
|
BLAKE2b-256 checksum How to use checksums |
3079a75e9129809368b3e3d9b9bc803230ac1cba7d690338f7b0c3ad46107fa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for clip-interrogator 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.