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
Release history Release notifications | RSS feed
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.3.tar.gz
(665.5 kB
view hashes)
Built Distribution
gradio_pdf-0.0.3-py3-none-any.whl
(305.2 kB
view hashes)
Close
Hashes for gradio_pdf-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10b7f7e13a4e4fc30ee83ffebf1e1603230eb9cc8708706508fc598d9c7ddeda |
|
MD5 | 39ad2ef758a846542e37c6e3660ab86a |
|
BLAKE2b-256 | 46b538e75ee383ea30d8ac332f909bdc0e06ec026d317eee4cfdb927ba455089 |