File size: 748 Bytes
d252d50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac829b
 
 
d252d50
 
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 pipeline

get_completion = pipeline("image-to-text",model="Salesforce/blip-image-captioning-base")
    
def captioner(image):
    result = get_completion(image)
    return result[0]['generated_text']

gr.close_all()
demo = gr.Interface(fn=captioner,
                    inputs=[gr.Image(label="Upload image", type="pil")],
                    outputs=[gr.Textbox(label="Caption")],
                    title="Image Captioning",
                    description="Generate a caption for any image",
                    allow_flagging="never",
                    examples=["data/dog.jpeg", 
                              "data/batman.jpg", 
                              "data/bricks.jpg"])

demo.launch()