-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 component custom component guide #6344
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/7d3ece8e4e9af57911fa6d3d32bb1e737c07e446/gradio-4.2.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@7d3ece8e4e9af57911fa6d3d32bb1e737c07e446#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
Make sure you have gradio 4.0 installed. | ||
As of the time of publication, the latest release is 4.1.1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gets outdated, I don't think we need to mention the specific version
Make sure you have gradio 4.0 installed. | |
As of the time of publication, the latest release is 4.1.1. | |
Make sure you have gradio 4.0 or higher installed (run `pip install --upgrade gradio`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its likely we're going to make improvements to the CLI experience or some internal APIs so I want to mention the version so that someone can follow this guide exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. We can upgrade to 4.2.0
ENV TRANSFORMERS_CACHE=/tmp/cache/ | ||
``` | ||
|
||
## Conclusion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can add a quick section on how to use this component in a Gradio app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you could use gr.Interface
with examples
to showcase the Example
version of the component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes intentional? I don't see the new Guide here btw: https://gradio-18ln1n3gs-hugging-face.vercel.app/guides
cc @aliabd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aliabd Changed this because otherwise new guides don't load. I see the new guide in the preview now

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm for some reason I still don't see it

And shouldn't they be pinned at the top as they are here? Or did you remove intentionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aliabd removed the pin at the top intentionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abidlabs are you checking on main? https://gradio-18ln1n3gs-hugging-face.vercel.app/main/guides
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah whoops you’re right, LGTM. Let’s do a release today to get this out
Very cool stuff @freddyaboulton! Just left a few comments above I think we can also close this issue: #2031 and provide an example of how to use this custom component there. |
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
* focus and blur events * format * add changeset * fixes * fixes * format --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* Fix upload * add changeset * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @freddyaboulton -- the only part that's not working for me is the website preview. Perhaps @aliabd could help us figure that out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this! Left a few nits but otherwise looks great! Thanks @freddyaboulton!
We're going to use the [pdfjs](https://mozilla.github.io/pdf.js/) javascript library to display the pdfs in the frontend. | ||
Let's start off by adding it to our frontend project's dependencies, as well as adding a couple of other projects we'll need. | ||
|
||
In the `dependencies` key, remove `svelte-json-view` and add the following dependencies: `@gradio/client`, `@gradio/upload`, `@gradio/icons`, `@gradio/button`, and `pdfjs-dist`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should tell them to npm install or pnpm install here. Adding dependencies manually is error prone.
It's fine to remove them manually but you can also npm uninstall package
This is the most advanced javascript part. | ||
It took me a while to figure it out! | ||
Do not worry if you have trouble, the important thing is to not be discouraged 💪 | ||
Ask for help in the gradio [discord](https://discord.gg/hugging-face-879548962464493619) if you need and ask for help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we create a channel on discord just for svelte/ js/ front end questions?
Thank you so much everyone!! |
Description
Closes #2031
We should have a series of step-by-step guides for creating custom components.
Rendering a PDF in js is actually tricky. So we should have easier guides too and order them by difficulty.
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh