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
Stop caching root url #7374
Stop caching root url #7374
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/fbfc2ba0f49759a92c639a6ba10ddf9b7c33b648/gradio-4.17.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@fbfc2ba0f49759a92c639a6ba10ddf9b7c33b648#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
Actually wait I think the cached examples are off |
Should be ready now! |
@@ -571,8 +570,8 @@ async def predict( | |||
content={"error": str(error) if show_error else None}, | |||
status_code=500, | |||
) | |||
root_path = app.get_blocks().config.get("root", "") | |||
output = add_root_url(output, route_utils.strip_url(root_path)) | |||
root_path = route_utils.get_root_url(request)[: -len(f"/api/{api_name}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoying to do this manually, but if you use e.g. request.url.path
, it also includes the root url if gradio is mounted within another fastapi app, which we don't want. So I think the most reliable solution is to just remove the suffix manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks @abidlabs ! Tested several demos and the root was properly set in all of them.
Thanks so much for the review @freddyaboulton! |
Fixes: #7372
The issue was that we were caching the "root_url" the first time the Gradio app was launched. I did this to speed things up, but the problem is that the same Gradio app can be launched on different URLs. For example, when you create a share link, you also might launch the Gradio app locally first (which would set the root_url to "localhost:7860") and then when you open the share link, the "root_url" will remain localhost:7860.
Now, we no longer cache the root url. I profiled this change and it adds pretty negligible latency for most demos (e.g.
2 ms
forkitchen_sink
). Does add more latency for very complex apps (150 ms
for thetheme_builder
) so maybe we should think of a better solution long-term (when we work on reducing the launch time).Also properly handles https & does some minor cleanup of this code.
You can confirm this works by visiting e.g. https://gradio-pr-deploys-pr-7374-all-demos.hf.space/demo/altair_plot/config and checking the "root" propery. Or to test locally, launch a Gradio demo with
share=True
and visit the/config
route and confirm that the "root" property is what you expect.