File size: 959 Bytes
6be7b31
 
 
 
f2f78db
6be7b31
 
 
 
 
 
 
 
 
 
 
 
 
4d542b9
 
 
6be7b31
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
import os
import io
from PIL import Image
from transformers import pipeline
import gradio as gr 

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

def summarize(input):
    output = get_completion(input)
    return output[0]['generated_text']

def captioner(image):
    result = get_completion(image)
    return result[0]['generated_text']

gr.close_all()

christmas_dog = "dog_animal_greyhound_983023.jpg"
bird = "bird_exotic_bird_green.jpg"
cow = "cow_animal_cow_head.jpg"

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