Python library for easily interacting with trained machine learning models
Project description
gradio_pdf
Display PDFs in Gradio!
Example usage
import gradio as gr
from gradio_pdf import PDF
from pdf2image import convert_from_path
from transformers import pipeline
from pathlib import Path
dir_ = Path(__file__).parent
p = pipeline(
"document-question-answering",
model="impira/layoutlm-document-qa",
)
def qa(question: str, doc: str) -> str:
img = convert_from_path(doc)[0]
output = p(img, question)
return sorted(output, key=lambda x: x["score"], reverse=True)[0]['answer']
demo = gr.Interface(
qa,
[gr.Textbox(label="Question"), PDF(label="Document")],
gr.Textbox(),
examples=[["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")]]
)
demo.launch()
Demo
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gradio_pdf-0.0.2.tar.gz
(663.6 kB
view hashes)
Built Distribution
gradio_pdf-0.0.2-py3-none-any.whl
(303.7 kB
view hashes)
Close
Hashes for gradio_pdf-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b00daed66f4b92d392a76917ebd3651726122b32f89a1a47654e6e4f09cc071c |
|
MD5 | f2a95b2df94d558e7b463f84ac316c77 |
|
BLAKE2b-256 | f31e9494dae13d770c477901f27da6f5b0b6a4a45c22e494e9ea57269e0faf90 |