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 pathlib import Path

dir_ = Path(__file__).parent


def qa(question: str, doc: str) -> str:
    return doc


demo = gr.Interface(
    qa,
    [gr.Textbox(label="Question"), PDF(label="Document",
                                       value=str(dir_ / "sample_invoice.pdf"))],
    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
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[..., 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.14.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

gradio_pdf-0.0.14-py3-none-any.whl (284.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gradio_pdf-0.0.14.tar.gz
Algorithm Hash digest
SHA256 2ca0e7a2719f02dde9b15720712178a131de623d67d72539833b8cac207a9625
MD5 9e9eeb88cae51d8239d835eb0c148d29
BLAKE2b-256 bd2339702941333209ce0c11a2ed323ac2be89bb013eb24978e101d727609e58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradio_pdf-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 284.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.12

File hashes

Hashes for gradio_pdf-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 0ec98dea4975b00d312ca6c660fd282c3d7e56ee499e9e56b44f57778629c852
MD5 3c5942c545f66daa137e7d0187a258ff
BLAKE2b-256 ddd0fd85d7ac8aeb209cc6a0a78fc3d26aea52044836d6ac79fbf64b4e270439

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