Spaces:
Runtime error
Runtime error
File size: 767 Bytes
da5f7bf | 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 30 31 32 33 34 35 36 37 38 | import gradio as gr
import json
from transformers import pipeline
from pytesseract import pytesseract
# Load the model
nlp = pipeline(
"document-question-answering",
model="impira/layoutlm-document-qa",
)
# Function to perform the question answering
def perform_question_answering(image, question):
answer = nlp(image, question)
# Format the answer as JSON
answer_json = json.dumps(answer, indent=4)
return answer_json
# Create the Gradio interface
inputs = [
gr.inputs.Image(type="pil", label="Upload Image"),
gr.inputs.Textbox(label="Question")
]
outputs = gr.outputs.Textbox(label="Answer")
iface = gr.Interface(fn=perform_question_answering, inputs=inputs, outputs="text")
# Launch the Gradio interface
iface.launch()
|