|
import requests |
|
from PIL import Image |
|
from transformers import BlipProcessor, BlipForConditionalGeneration |
|
|
|
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") |
|
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").to("cuda") |
|
|
|
img_url = 'https://www.chitramala.in/wp-content/gallery/pawan-kalyan-pspk25-movie-working-stills/PSPK-25-Movie-Location-Photos-5.jpg' |
|
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB') |
|
|
|
|
|
text = "a photography of" |
|
inputs = processor(raw_image, text, return_tensors="pt").to("cuda") |
|
|
|
out = model.generate(**inputs) |
|
print(processor.decode(out[0], skip_special_tokens=True)) |
|
|
|
|
|
|
|
inputs = processor(raw_image, return_tensors="pt").to("cuda") |
|
|
|
out = model.generate(**inputs) |
|
print(processor.decode(out[0], skip_special_tokens=True)) |
|
|