Visual_Q_and_A / app.py
captain-awesome's picture
Create app.py
1a838e7 verified
raw
history blame
788 Bytes
import gradio as gr
from transformers.utils import logging
logging.set_verbosity_error()
import warnings
warnings.filterwarnings("ignore", message="Using the model-agnostic default `max_length`")
from transformers import BlipForQuestionAnswering
from transformers import AutoProcessor
def qa(inputs):
model = BlipForQuestionAnswering.from_pretrained(
"./models/Salesforce/blip-vqa-base")
processor = AutoProcessor.from_pretrained(
"./models/Salesforce/blip-vqa-base")
inputs = processor(image, question, return_tensors="pt")
out = model.generate(**inputs)
return processor.decode(out[0], skip_special_tokens=True)
# def greet(name):
# return "Hello " + name + "!!"
iface = gr.Interface(fn=qa, inputs=["image","text"], outputs="text")
iface.launch()