-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg2txt.py
21 lines (18 loc) · 848 Bytes
/
img2txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import pipeline
get_caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
def caption(img):
if not img:
pass
else:
output = get_caption(img)
return output[0]["generated_text"]
interface_img2txt = gr.Interface(fn=caption,
inputs=gr.Image(label="Image", type='pil'),
outputs=gr.Textbox(label="Caption"),
examples=["imgs/car.jpg", "imgs/tiger.jpg", "imgs/swan.jpg"],
title="Image captioning",
description="Get a image caption.",
css="footer{display:none !important}",
allow_flagging="never"
)