# `gradio_pdf` Python library for easily interacting with trained machine learning models ## Installation ```bash pip install gradio_pdf ``` ## Usage ```python 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")]] ) if __name__ == "__main__": demo.launch() ``` ## `PDF` ### Initialization
name | type | default | description |
---|---|---|---|
value |
```python Any ``` | None |
None |
height |
```python int | None ``` | None |
None |
label |
```python str | None ``` | None |
None |
info |
```python str | None ``` | None |
None |
show_label |
```python bool | None ``` | None |
None |
container |
```python bool ``` | True |
None |
scale |
```python int | None ``` | None |
None |
min_width |
```python int | None ``` | None |
None |
interactive |
```python bool | None ``` | None |
None |
visible |
```python bool ``` | True |
None |
elem_id |
```python str | None ``` | None |
None |
elem_classes |
```python list[str] | str | None ``` | None |
None |
render |
```python bool ``` | True |
None |
load_fn |
```python Callable[Ellipsis, Any] | None ``` | None |
None |
every |
```python float | None ``` | None |
None |