File size: 629 Bytes
80fdd4f
 
74cad3c
80fdd4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import BlipForConditionalGeneration
from transformers import AutoProcessor

model = BlipForConditionalGeneration.from_pretrained(
    "Salesforce/blip-image-captioning-base")

processor = AutoProcessor.from_pretrained(
    "Salesforce/blip-image-captioning-base")


def image_caption(input):
    inputs = processor(input, return_tensors="pt")
    out = model.generate(**inputs)
    return processor.decode(out[0], skip_special_tokens = True)


iface = gr.Interface(fn = image_caption,
                     inputs = gr.Image(type='pil'),
                     outputs = "text")

iface.launch()