File size: 670 Bytes
68577fd
d228026
ae0e292
 
68577fd
 
 
036c445
68577fd
 
 
 
 
 
8bbfc13
68577fd
 
 
 
 
b488b6f
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 BlipProcessor, BlipForConditionalGeneration
from PIL import Image

def generate_caption(input_image):
    processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") 
    model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
    inputs = processor(input_image, return_tensors="pt")
    outputs = model.generate(**inputs)
    caption = processor.decode(outputs[0], skip_special_tokens=True)
    return caption

iface = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image( type = "pil"),
    outputs="text",
    title="Image Captioning",
)

iface.launch()