File size: 947 Bytes
37e1eef d842fb9 37e1eef d842fb9 37e1eef |
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 |
import os
import gradio as gr
from transformers import pipeline
from transformers import AutoProcessor, BlipForQuestionAnswering
processor = AutoProcessor.from_pretrained(
"Salesforce/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained(
"Salesforce/blip-vqa-base")
def launch(pil_image, question):
inputs = processor(pil_image, question, return_tensors="pt")
out = model.generate(**inputs)
return processor.decode(out[0], skip_special_tokens=True)
iface = gr.Interface(fn=launch,
inputs=[gr.Image(label="Input image", type='pil'),
gr.Textbox(label="Question", lines=3)],
outputs=gr.Textbox(label="Answer", lines=3),
title="Image Q&A with Salesforce BLIP",
description="Get answers on questions about any image using the BLIP model",
allow_flagging="never",
iface.launch() |