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 component custom component guide #6344

Merged
merged 17 commits into from Nov 13, 2023
Merged

Conversation

freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Nov 8, 2023

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

  1. 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

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 8, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

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"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 8, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
website minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

PDF component custom component guide

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@freddyaboulton freddyaboulton changed the title WIP: PDF component custom component guide PDF component custom component guide Nov 9, 2023
@freddyaboulton freddyaboulton marked this pull request as ready for review November 9, 2023 21:32
Comment on lines 7 to 8
Make sure you have gradio 4.0 installed.
As of the time of publication, the latest release is 4.1.1.
Copy link
Member

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

Suggested change
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`).

Copy link
Collaborator Author

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea good idea!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

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

Copy link
Member

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

Copy link
Collaborator Author

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

image

Copy link
Member

@abidlabs abidlabs Nov 13, 2023

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

image

And shouldn't they be pinned at the top as they are here? Or did you remove intentionally

Copy link
Collaborator Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

@abidlabs
Copy link
Member

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.

freddyaboulton and others added 3 commits November 10, 2023 10:06
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>
freddyaboulton and others added 4 commits November 10, 2023 11:20
* Fix upload

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Copy link
Member

@abidlabs abidlabs left a 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

Copy link
Member

@pngwn pngwn left a 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`.
Copy link
Member

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

guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
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.
Copy link
Member

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?

Cc @yvrjsharma @abidlabs

guides/05_custom-components/07_pdf-component-example.md Outdated Show resolved Hide resolved
@freddyaboulton
Copy link
Collaborator Author

Thank you so much everyone!!

@freddyaboulton freddyaboulton merged commit 7471970 into main Nov 13, 2023
13 checks passed
@freddyaboulton freddyaboulton deleted the pdf-component-case-study branch November 13, 2023 19:52
@pngwn pngwn mentioned this pull request Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDF display in a block
7 participants