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

Lite auto-load imported modules with pyodide.loadPackagesFromImports #9726

Merged
merged 10 commits into from
Nov 4, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Oct 16, 2024

Description

Resolves #9701.
Auto-load (some) modules based on the import statements obtained by the AST analysis.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 16, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/7901d7510b6ff2cee142eec5811080c023338b80/gradio-5.4.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@7901d7510b6ff2cee142eec5811080c023338b80#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/7901d7510b6ff2cee142eec5811080c023338b80/gradio-client-1.7.1.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/7901d7510b6ff2cee142eec5811080c023338b80/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 16, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/lite minor
@gradio/wasm minor
gradio minor
website minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Lite auto-load imported modules with pyodide.loadPackagesFromImports

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.

@whitphx whitphx changed the title Lite auto load modules Lite auto-load imported modules with pyodide.loadPackagesFromImports Oct 16, 2024
@whitphx whitphx marked this pull request as ready for review October 17, 2024 06:57
Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

@whitphx this looks good to me! nice work.

Can you explain what you mean by "some" libraries? I assumed we can now move off of having the LLM generate the requirements.

Also if not a big deal, can we add the libraries we auto import to the requirements tab in the playground? would reduce confusion and also if users deploy to spaces with the button it will grab them correctly as well.

@whitphx
Copy link
Member Author

whitphx commented Nov 4, 2024

@aliabd Thanks!
This AST-based approach can auto-load only the packages built in the Pyodide distribution

At present, loadPackagesFromImports() will not download packages from PyPI, it will only download packages included in the Pyodide distribution. See Packages built in Pyodide to check the full list of packages included in Pyodide.
https://pyodide.org/en/stable/usage/loading-packages.html

So we need to keep the LLM-based requirements generator as well and use both so they complement each other.

  • AST-based:
    • Pros: programmatic and precise.
    • Cons: limited packages
  • LLM-based:
    • Pros: possible to cover all packages
    • Cons: less precise, hallucination

can we add the libraries we auto import to the requirements tab in the playground?

It's already implemented here: https://github.com/gradio-app/gradio/pull/9726/files#diff-dfae75e4bcb0e1b634f9f9986a9fadc1045e690ad6548bb5c6870f2796bb3126R280-R287
Probably the problem is that it's slow and users can't easily notice it? We may improve the UI/UX...

@aliabd
Copy link
Collaborator

aliabd commented Nov 4, 2024

Got it, thanks @whitphx!

@abidlabs
Copy link
Member

abidlabs commented Nov 4, 2024

Merging in for the release!

@abidlabs abidlabs merged commit b6725cf into main Nov 4, 2024
23 of 24 checks passed
@abidlabs abidlabs deleted the lite-auto-load-modules branch November 4, 2024 21:50
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.

Lite: AST-based imports extraction and auto-load
4 participants