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(doc: str, question: 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,
[PDF(label="Document"), gr.Textbox()],
gr.Textbox(),
examples=[[str(dir_ / "invoice_2.pdf"), "What is the total gross worth?"]]
)
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.1.tar.gz
(431.7 kB
view hashes)
Built Distribution
gradio_pdf-0.0.1-py3-none-any.whl
(69.1 kB
view hashes)
Close
Hashes for gradio_pdf-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1513759206a38f8184c5123a3b4d94799a28e6b84081553f690c957ae6f70951 |
|
MD5 | 25644c5c4b0dd5bc0710e4eb6ca3e037 |
|
BLAKE2b-256 | d957feb9b9fa744cdb6ea2b7344cdc6ea5034a95cd1d3995f6391ee06599c2f2 |