GitXplorerGitXplorer
f

gradio-pdf

public
23 stars
8 forks
6 issues

Commits

List of commits on branch main.
Unverified
5ee235b4fb4748e9fbbd674d18572610acc94333

Bump version

ffreddyaboulton committed a month ago
Verified
0226880c8d29c2c7e99aa20c046444bc689c2ba1

Merge pull request #34 from freddyaboulton/fix-chinese-character-issue

ffreddyaboulton committed a month ago
Unverified
daad0893af211ca3992cbce2a0d93509b798ba86

Add code

ffreddyaboulton committed a month ago
Verified
fe2330b7ac1693aaa4bf22b34988d2890b77ec6f

Merge pull request #32 from freddyaboulton/fix-interactive-change-firing-twice

ffreddyaboulton committed a month ago
Unverified
347673df880b7cf49ce10e2db4836d968e162f3b

version bump

ffreddyaboulton committed a month ago
Unverified
21f3cf948da84320935f40ea6931d91a0e7df0d5

Fix bugs

ffreddyaboulton committed a month ago

README

The README file for this repository.

Gradio PDF 📕

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