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

Support gr.load()-ing Gradio apps with Blocks.load() events #10324

Merged
merged 10 commits into from
Jan 10, 2025
Merged

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Jan 9, 2025

And some minor cleanup. Closes: #10312

Test with something like this:

import gradio as gr

with gr.Blocks() as demo:
    with gr.Blocks() as demo_:
        t = gr.Textbox()
        demo_.load(lambda : "Hello", None, t)


gr.Blocks.from_config(demo.get_config_file(), fns=[lambda : "Hello"], proxy_url="").launch()

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jan 9, 2025

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/d6ff0183e7b262b68868a8659095330065daf1b0/gradio-5.11.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/d6ff0183e7b262b68868a8659095330065daf1b0/gradio-client-1.9.0.tgz

Use Lite from this PR

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

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jan 9, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Support gr.load()-ing Gradio apps with Blocks.load() events

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.

@abidlabs abidlabs changed the title Support gr.load()-ing a gr.ChatInterface Support gr.load()-ing Gradio apps with Blocks.load() events Jan 10, 2025
@abidlabs abidlabs marked this pull request as ready for review January 10, 2025 15:41
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Nice fix @abidlabs - left some minor comments

gradio/blocks.py Outdated
# Any event -- e.g. Blocks.load() -- that is triggered by this Blocks
# should now be triggered by the root Blocks instead.
for target in dependency.targets:
print("target", target, "self._id", self._id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove print

gradio/blocks.py Outdated
@@ -3008,3 +3007,29 @@ def get_api_info(self, all_endpoints: bool = False) -> dict[str, Any] | None:
api_info["named_endpoints"][f"/{fn.api_name}"] = dependency_info

return api_info

@staticmethod
def get_target_events(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit but I feel like get_event_targets is a more accurate name

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed

@abidlabs
Copy link
Member Author

Thanks @freddyaboulton! Addressed suggestions

@abidlabs abidlabs enabled auto-merge (squash) January 10, 2025 18:04
@abidlabs abidlabs merged commit 343503d into main Jan 10, 2025
22 checks passed
@abidlabs abidlabs deleted the load-ci branch January 10, 2025 18:14
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.

With additional inputs and/or save history the loading of another Gradio throws error.
3 participants