File size: 783 Bytes
4681c0f
 
 
 
6d63790
4681c0f
8677416
4681c0f
 
 
8677416
 
 
4681c0f
8677416
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
from transformers import pipeline

pipe = pipeline("image-to-text",
                model="Salesforce/blip-image-captioning-base")

def captioner(input):
    out = pipe(input)
    return out[0]['generated_text']

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

# iface.launch()

demo = gr.Interface(fn=captioner,
                    inputs=[gr.Image(label="Upload image", type="pil")],
                    outputs=[gr.Textbox(label="Caption")],
                    title="Image Captioning with BLIP",
                    description="Caption any image using the BLIP model",
                    allow_flagging="never",
                    examples=["christmas_dog.jpg"])

demo.launch()