Gradio PDF

raw JSON →
0.0.24 verified Fri May 01 auth: no python

Gradio component to display PDF files and extract text within Gradio apps. Currently at version 0.0.24, with a pre-1.0 release cadence. Requires Python >=3.10.

pip install gradio-pdf
error ModuleNotFoundError: No module named 'gradio_pdf'
cause Package not installed or installed with wrong name.
fix
Run pip install gradio-pdf. Note the hyphen in the package name but underscore in imports.
error ImportError: cannot import name 'Pdf' from 'gradio_pdf'
cause The class name changed from 'Pdf' to 'PDF' in version 0.0.22.
fix
Use from gradio_pdf import PDF (uppercase).
error AttributeError: module 'gradio_pdf' has no attribute 'PDF'
cause Old version (<0.0.22) used 'Pdf' instead of 'PDF'. Or the import statement is incorrect.
fix
Upgrade to latest version: pip install --upgrade gradio-pdf. Then use from gradio_pdf import PDF.
breaking The import path changed from `gradio_pdf import Pdf` to `gradio_pdf import PDF` in version 0.0.22. Old code will raise ImportError.
fix Use `from gradio_pdf import PDF` (capital 'PDF').
deprecated The `render` method was deprecated in v0.0.20 and removed in v0.0.22. Use the component directly in Blocks.
fix Place the PDF component inside `gr.Blocks()` as `PDF(...)`, not `PDF().render()`.
gotcha The `value` parameter expects a file path or URL as a string, not a file object. Passing a file object may cause silent failure.
fix Always pass a string path or URL: `PDF(value='/path/to/file.pdf')`.

Simple Gradio app with PDF component (placeholder; see official docs for full PDF usage).

import gradio as gr
from gradio_pdf import PDF

def greet(name):
    return f"Hello {name}!"

with gr.Blocks() as demo:
    name = gr.Textbox(label="Name")
    output = gr.Textbox(label="Output")
    greet_btn = gr.Button("Greet")
    greet_btn.click(fn=greet, inputs=name, outputs=output)

demo.launch()