mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-12-25 05:48:55 +01:00
1622059179
It's just as fast
14 lines
602 B
Python
14 lines
602 B
Python
import requests
|
|
import torch
|
|
from PIL import Image
|
|
from transformers import BlipForConditionalGeneration
|
|
from transformers import BlipProcessor
|
|
|
|
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float32).to("cpu")
|
|
|
|
def caption_image(raw_image):
|
|
inputs = processor(raw_image.convert('RGB'), return_tensors="pt").to("cpu", torch.float32)
|
|
out = model.generate(**inputs, max_new_tokens=100)
|
|
return processor.decode(out[0], skip_special_tokens=True)
|