from transformers import pipeline import gradio as gr from PIL import Image nlp = pipeline( "document-question-answering", model="impira/layoutlm-document-qa", ) def vqa(image, question): inp = Image.fromarray(image.astype('uint8'), 'RGB') return nlp(inp, question) demo = gr.Interface(fn=vqa, inputs=['image', 'text'], outputs='text', title = "vqa", examples = [['income.png', 'What are the 2020 net sales?'], ['invoice.png','What is the invoice number?']]) if __name__ == "__main__": demo.queue(concurrency_count=3).launch(server_name = "0.0.0.0", server_port = 7025)