Skip to main content

Easily display PDFs in Gradio

Project description

gradio_pdf

PyPI - Version Static Badge Static Badge

Easily display PDFs in Gradio

Installation

pip install gradio_pdf

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:
   return doc


demo = gr.Interface(
    qa,
    [PDF(label="Document")],
    PDF(),
    examples=[[str((dir_ / "invoice_2.pdf").resolve())],
              [str((dir_ / "sample_invoice.pdf").resolve())]]
)

if __name__ == "__main__":
    demo.launch()

PDF

Initialization

name type default description
value
Any
None None
height
int | None
None None
label
str | None
None None
info
str | None
None None
show_label
bool | None
None None
container
bool
True None
scale
int | None
None None
min_width
int | None
None None
interactive
bool | None
None None
visible
bool
True None
elem_id
str | None
None None
elem_classes
list[str] | str | None
None None
render
bool
True None
load_fn
Callable[Ellipsis, Any] | None
None None
every
float | None
None None
starting_page
int | None
1 None

Events

name description
change
upload

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, the preprocessed input data sent to the user's function in the backend.
  • As input: Should return, the output data received by the component from the user's function in the backend.
def predict(
    value: str
) -> str | None:
    return value

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.17.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

gradio_pdf-0.0.17-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file gradio_pdf-0.0.17.tar.gz.

File metadata

  • Download URL: gradio_pdf-0.0.17.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.13

File hashes

Hashes for gradio_pdf-0.0.17.tar.gz
Algorithm Hash digest
SHA256 2e855cc04ede19c2b935ceaa2939eb9c8fab365b036de9212943fe173ab6490f
MD5 def040056d97253b8f771ad1a90b5213
BLAKE2b-256 6c39fd3f4a1c02bdc08331e7ee8ee445848c16e1242497de23c10672d7db5411

See more details on using hashes here.

File details

Details for the file gradio_pdf-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: gradio_pdf-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.13

File hashes

Hashes for gradio_pdf-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 377e69219358512c5fdcf057aa9bd1c7d6ab44309b21c47381445fc3e6a3fc88
MD5 24092ad63894229e102a7950f1b4f43e
BLAKE2b-256 575c333239d8b0f921f81612ee5baada46ea41462bb0defa9e391cf90d82ecea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page