Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF display in a block #2031

Closed
BouzidiImen opened this issue Aug 17, 2022 · 6 comments · Fixed by #6344
Closed

PDF display in a block #2031

BouzidiImen opened this issue Aug 17, 2022 · 6 comments · Fixed by #6344
Labels
new component Involves creating a new component

Comments

@BouzidiImen
Copy link

BouzidiImen commented Aug 17, 2022

  • I have searched to see if a similar issue already exists but I can't find any solution.
  • I am working on a dashboard to demo a model that classifies articles and output tags, and I need the users to correct the results/output of the model.

Solution
I would like to have a feature that allows the display of a pdf file on the dashboard.

@abidlabs
Copy link
Member

Thanks @BouzidiImen for the suggestion. Agree that this would be a useful component!

@abidlabs abidlabs added the new component Involves creating a new component label Aug 17, 2022
@abidlabs abidlabs added this to the Gradio 4.0 milestone Feb 21, 2023
@abidlabs abidlabs removed this from the 4.0 milestone May 25, 2023
@fazpu
Copy link
Contributor

fazpu commented Jul 28, 2023

https://github.com/vinodnimbalkar/svelte-pdf could be a good candidate for integration

@pseudotensor
Copy link
Contributor

Any thoughts on this @abidlabs ?

@abidlabs
Copy link
Member

abidlabs commented Nov 7, 2023

Hi! We've now made it possible for Gradio users to create their own custom components -- meaning that you can write some Python and JavaScript (Svelte), and publish it as a Gradio component. You can use it in your own Gradio apps, or share it so that anyone can use it in their Gradio apps. Here are some examples of custom Gradio components:

You can see the source code for those components by clicking the "Files" icon and then clicking "src". The complete source code for the backend and frontend is visible. In particular, its very fast if you want to build off an existing component. We've put together a Guide: https://www.gradio.app/guides/five-minute-guide, and we're happy to help if you'd like to put together a custom component for this issue

@freddyaboulton
Copy link
Collaborator

freddyaboulton commented Nov 13, 2023

This is now possible with the gradio_pdf custom component available in version 4.

You can see it live on HuggingFace spaces here: https://huggingface.co/spaces/freddyaboulton/gradio_pdf

Install with pip install gradio_pdf and get started!

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")]]
)

demo.launch()

@MousumiSahaDXC
Copy link

MousumiSahaDXC commented Jan 16, 2025

Hi @freddyaboulton Many thanks to you for building this. How to use gradio-pdf to upload multiple pdfs together and also display them in a single upload click .
Something like the one shown in the attached image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new component Involves creating a new component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants