Skip to content

Pass any visible error modals from a Gradio app downstream to the app that has gr.load-ed it #11043

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

Merged
merged 14 commits into from
Apr 17, 2025

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Apr 16, 2025

Suppose Gradio app A uses gr.load() to load a Gradio app B.

With this change, if Gradio app B raises a visible error, which means either:

  • It raises a gr.Error, or
  • It raises any type of exception and show_error=True in launch()

Then, the error will be visible in Gradio app B (with the usual error modal).

Test with:

import gradio as gr

gr.load("gradio/calculator", src="spaces").launch()

and try doing 0/0 for example.

Closes: #10364

cc @cbensimon for visibility

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Apr 16, 2025

🪼 branch checks and previews

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

Install Gradio from this PR

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

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/f9007915d2dcacea007f193a72d4e93867a076be/gradio-client-1.14.2.tgz

Use Lite from this PR

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

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Apr 16, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Pass any visible error modals from a Gradio app downstream to the app that has gr.load-ed it

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 Client error Pass any visible error modals from a Gradio app downstream to the app that has gr.load-ed it Apr 16, 2025
@abidlabs abidlabs marked this pull request as ready for review April 16, 2025 21:08
@abidlabs abidlabs marked this pull request as draft April 16, 2025 21:09
@cbensimon
Copy link
Contributor

Tested and working as expected : https://huggingface.co/spaces/cbensimon/gr-load-test

But for some reason the app itself is not working properly (not related to this PR). If you try it you'll see that the generated image gets a 404 not found (maybe that the Space targeted by gr.load is using a too old Gradio)

@abidlabs abidlabs marked this pull request as ready for review April 17, 2025 17:19
@abidlabs
Copy link
Member Author

Thanks @cbensimon for testing and confirming! I'll take a look at that Space when I get a chance

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!

@@ -57,7 +58,7 @@ class GradioVersionIncompatibleError(Exception):


@document(documentation_group="modals")
class Error(Exception):
class Error(AppError):
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 think AppError should subclass Exception instead of ValueError ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably right, but I don't think it's a big deal and would be a breaking change for anyone building on top of the Gradio Client who's catching a ValueError. I've added it here: #10471

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if you're trying to catch AppErrors in your client code, you would catch AppError explicitly as opposed to catching ValueErrors generally but sound good it's a minor point!

gradio/utils.py Outdated
if show_error:
if isinstance(error, Error):
if isinstance(error, (Error, AppError)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it just be AppError if Error inherits from AppError?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@freddyaboulton
Copy link
Collaborator

Oops thought I had approved before

@abidlabs
Copy link
Member Author

Thanks folks!

@abidlabs abidlabs merged commit 62a0080 into main Apr 17, 2025
22 checks passed
@abidlabs abidlabs deleted the client-error branch April 17, 2025 19:34
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.

Forward gr.Error exception class from gradio_client.Client.predict
4 participants