Spaces:
Sleeping
Sleeping
File size: 670 Bytes
fd6e0b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from transformers import BlipProcessor, BlipForConditionalGeneration
import os
import gradio as gr
caption_model = 'Salesforce/blip-image-captioning-base'
processor = BlipProcessor.from_pretrained(caption_model)
model = BlipForConditionalGeneration.from_pretrained(caption_model)
def launch(input):
# proprocess text to prepare for the model
inputs = processor(input, return_tensors="pt")
output = model.generate(**inputs)
cond_caption = processor.decode(output[0], skip_special_tokens=True)
return cond_caption
iface = gr.Interface(launch,
inputs=gr.Image(type='pil'),
outputs="text")
# launch demo
iface.launch() |