|
import gradio as gr |
|
import requests |
|
from PIL import Image |
|
from transformers import BlipProcessor, BlipForConditionalGeneration |
|
|
|
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large") |
|
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large") |
|
|
|
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') |
|
|
|
|
|
text = "a photography of" |
|
inputs = processor(raw_image, text, return_tensors="pt") |
|
|
|
out = model.generate(**inputs) |
|
print(processor.decode(out[0], skip_special_tokens=True)) |
|
|
|
|
|
inputs = processor(raw_image, return_tensors="pt") |
|
|
|
out = model.generate(**inputs) |
|
print(processor.decode(out[0], skip_special_tokens=True)) |
|
|
|
gr.load("models/Salesforce/blip-image-captioning-large").launch() |