blip image2promt stable diffusion base

Providerifmain
Categoryimage-generation
LicenseApache-2.0
Downloads22
Stars0

Overview

The BLIP image2prompt model is a specialized vision-language tool designed to reverse-engineer text prompts from existing images, specifically optimized for Stable Diffusion workflows. For developers building generative art pipelines, this model solves the 'prompt engineering' bottleneck by analyzing visual compositions and translating them into descriptive tokens that the Stable Diffusion base model can interpret. Instead of manual guessing, you can integrate this into your preprocessing layer to automate image-to-image consistency or build automated captioning tools. It functions as a bridge between raw pixels and latent space descriptions, making it highly effective for creating training datasets or refining style transfers without extensive manual labeling.

Highlights

  • Translates images into Stable Diffusion compatible text prompts
  • Automates descriptive captioning for generative AI pipelines
  • Open-source integration via Apache-2.0 license
  • Optimized for reverse-engineering visual styles and compositions

Usage

Install
# Install Hugging Face transformers
pip install transformers torch
SDK Usage
# Load model with transformers
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("ifmain/blip-image2promt-stable-diffusion-base")
tokenizer = AutoTokenizer.from_pretrained("ifmain/blip-image2promt-stable-diffusion-base")

Hugging Face Download

We recommend downloading the model via the Hugging Face CLI or Hub SDK.

Guidance:Before downloading, install huggingface_hub with:

Guidance
pip install -U huggingface_hub

CLI Download

Download the full repository

Download the full repository
huggingface-cli download ifmain/blip-image2promt-stable-diffusion-base

Download a single file to a local folder (e.g. config.json into ./dir)

Download a single file to a local folder (e.g. config.json into ./dir)
huggingface-cli download ifmain/blip-image2promt-stable-diffusion-base config.json --local-dir ./dir

See the official docs for more CLI options

SDK Download

SDK Download
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('ifmain/blip-image2promt-stable-diffusion-base')

Git Download

Make sure git-lfs is installed first

Git Download
git lfs install
git clone https://huggingface.co/ifmain/blip-image2promt-stable-diffusion-base

To skip LFS large-file downloads, use:

Skip LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/ifmain/blip-image2promt-stable-diffusion-base

Model files are hosted on the Hugging Face Hub — download directly via HF CLI / SDK / Git, not through this site.

PyTorch / Transformers Usage

Install Transformers

Install Transformers
pip install -U transformers torch

Load the model and run inference

Load the model and run inference
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('ifmain/blip-image2promt-stable-diffusion-base')
tokenizer = AutoTokenizer.from_pretrained('ifmain/blip-image2promt-stable-diffusion-base')

Full Documentation

来源: HuggingFace

---
datasets:

  • Ar4ikov/civitai-sd-337k

language:
  • en

pipeline_tag: image-to-text
base_model: Salesforce/blip-image-captioning-base
---

Licence

license inherited from Salesforce/blip-image-captioning-base

Overview

ifmain/blip-image2promt-stable-diffusion-base is a model based on Salesforce/blip-image-captioning-base, trained on the Ar4ikov/civitai-sd-337k dataset (2K images). This model is designed to generate text descriptions of images in the style of prompts for use with Stable Diffusion models.

I used my Blip training code: BLIP-Easy-Trainer

Example Usage

python
import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
import re

def prepare(text):
text = text.replace('. ','.').replace(' .','.')
text = text.replace('( ','(').replace(' (','(')
text = text.replace(') ',')').replace(' )',')')
text = text.replace(': ',':').replace(' :',':')
text = text.replace('_ ','_').replace(' _','_')
text = text.replace(',(())','').replace('(()),','')
for i in range(10):
text = text.replace(')))','))').replace('(((','((')
text = re.sub(r'<[^>]*>', '', text)
return text

path_to_model = "ifmain/blip-image2promt-stable-diffusion-base"

processor = BlipProcessor.from_pretrained(path_to_model)
model = BlipForConditionalGeneration.from_pretrained(path_to_model, torch_dtype=torch.float16).to("cuda")

img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')

unconditional image captioning

inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)

out = model.generate(**inputs, max_new_tokens=100)

out_txt = processor.decode(out[0], skip_special_tokens=True)

print(prepare(out_txt)) # woman sitting on the beach at sunset, rear view,((happy)),((happy)),((dog)),((mixed)),(()),((

Addition

This model support SFW and NSFW content

Join our Telegram