gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Lite auto-load imported modules with `pyodide.loadPackagesFromImports`

Open whitphx opened this issue 1 year ago • 2 comments

Description

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

whitphx avatar Oct 16 '24 15:10 whitphx

🪼 branch checks and previews

• Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
:unicorn: 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 avatar Oct 16 '24 15:10 gradio-pr-bot

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

gradio-pr-bot avatar Oct 16 '24 15:10 gradio-pr-bot

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

whitphx avatar Nov 04 '24 20:11 whitphx

Got it, thanks @whitphx!

aliabd avatar Nov 04 '24 21:11 aliabd

Merging in for the release!

abidlabs avatar Nov 04 '24 21:11 abidlabs