-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_cap.py
29 lines (24 loc) · 839 Bytes
/
image_cap.py
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
import os
import io
import IPython.display
from PIL import Image
import base64
from transformers import pipeline
import gradio as gr
import warnings
warnings.filterwarnings("ignore")
task = "image-to-text"
model = "Salesforce/blip-image-captioning-base"
image_captioner = pipeline("image-to-text", model = "Salesforce/blip-image-captioning-base")
def captioner(image):
result = image_captioner(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 with BLIP",
description="Caption any image using the BLIP model",
allow_flagging="never",
)
demo.launch()