Skip to main content

gradio_pdf_redaction

Static Badge Static Badge Static Badge

Easily display PDFs in Gradio. Forked from Freddy Boulton's gradio_pdf repo: https://github.com/freddyaboulton/gradio-pdf

Installation

pip install gradio_pdf_redaction

Usage

import gradio as gr
from gradio_pdf_redaction 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']


EXAMPLES = [
    ["What is the total gross worth?", str(dir_ / "invoice_2.pdf")],
    ["Whos is being invoiced?", str(dir_ / "sample_invoice.pdf")],
]


def create_demo():
    return gr.Interface(
        qa,
        [gr.Textbox(label="Question"), PDF(label="Document")],
        gr.Textbox(),
        examples=EXAMPLES,
        cache_examples=False,
    )


# Required for `gradio cc dev` hot reload — must be a module-level Blocks/Interface.
demo = create_demo()

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

PDF

Initialization

name type default description
value
typing.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
typing.Optional[typing.Callable[..., typing.Any]][
    typing.Callable[..., typing.Any][Ellipsis, typing.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

Metadata

Release files for gradio-pdf-redaction 0.0.25

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradio-pdf-redaction 0.0.25
File Size Uploaded Provenance Actions
gradio_pdf_redaction-0.0.25.tar.gz 1.2 MB Without provenance Details for gradio_pdf_redaction-0.0.25.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gradio-pdf-redaction 0.0.25
File Interpreter ABI Platform Actions
gradio_pdf_redaction-0.0.25-py3-none-any.whl Python 3 none any Details for gradio_pdf_redaction-0.0.25-py3-none-any.whl

Total release size: 1.5 MB

Release files / gradio_pdf_redaction-0.0.25.tar.gz

Download URL gradio_pdf_redaction-0.0.25.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
94f601e2c571e13e69331f2091b209ae1235fe3bdf971a2e11cd6e7d6bc1f2ec
BLAKE2b-256 checksum
How to use checksums
459e4e7bb89f51aa9c251cc0c28594e1189ae8b50e0a89812cc7494aeca79cf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / gradio_pdf_redaction-0.0.25-py3-none-any.whl

Download URL gradio_pdf_redaction-0.0.25-py3-none-any.whl
Size 376.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7f252b4af765dfcd0487e7debb3af0fcbba4324eca7cb2f2495c0b34b8dbd2b
BLAKE2b-256 checksum
How to use checksums
820025ff0100d98d2879de5cbb8056357cd16dd9812be44c94d103fd0759f6ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Security for gradio-pdf-redaction 0.0.25

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.25 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page