Prevent api requests from skipping queue#2493
Conversation
3c597bc to
6a50df4
Compare
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2493-all-demos |
6a50df4 to
5f6b984
Compare
| utils.run_coro_in_background(self._queue.start) | ||
| utils.run_coro_in_background(self.create_limiter) | ||
|
|
||
| def queue_enabled_for_fn(self, fn_index: int): |
There was a problem hiding this comment.
Just a refactor to reduce dupe code
| if not app.blocks.api_open and app.blocks.queue_enabled_for_fn( | ||
| body.fn_index | ||
| ): | ||
| if f"Bearer {app.queue_token}" != request.headers.get("Authorization"): |
There was a problem hiding this comment.
I think Bearer {token} in the Authorization header is the standard way of providing these tokens.
| self.share_url = None | ||
| self.width = None | ||
| self.height = None | ||
| self.api_open = False |
There was a problem hiding this comment.
My feeling is that the API should be open by default to preserve the current behavior.
| client_position_to_load_data: Once a client's position in Queue is less that this value, the Queue will collect the input data from the client. You may make this smaller if clients can send large volumes of data, such as video, since the queued data is stored in memory. | ||
| default_enabled: If True, all event listeners will use queueing by default. | ||
| api_open: If True, the REST routes of the backend will be open, allowing requests made directly to those endpoints to skip the queue. | ||
| max_size: The maximum number of events the queue will store at any given moment. |
|
Thanks @freddyaboulton, this looks really good to me. One addition: can we hide the "view API" page link in the footer if queue is enabled and |
|
This is also very timely as we currently have issues with an app on Spaces whose API endpoint is being called from an external endpoint, degrading the experience for regular users of the Space. I'm going to release a beta version so that we can try this out on the Space itself. cc @AK391 @osanseviero Internal discussion: https://huggingface.slack.com/archives/C02136Y252P/p1666447456974249 Also did some more testing and confirmedthat if you have a Space that sets |
f862b9f to
ac1de7d
Compare
|
@abidlabs I made it so that the api is open by default and api_open will take precedence over show_api if the queue is enabled! Should be good for another look now! |
|
LGTM @freddyaboulton very nice PR! |
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
3444743 to
11c008b
Compare
|
Thank you for the review @abidlabs ! |
Description
Fixes #2452
Summary:
/apiendpoint will be blocked if the queue is enabled for that event, unless a special auth token is passed in the header. This is to allow the queue to make requests.queue(api_open=True).Added some unit tests but you can test yourself as well:
In a separate process
Checklist:
A note about the CHANGELOG
Hello 👋 and thank you for contributing to Gradio!
All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.
Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by
[@myusername](link-to-your-github-profile)in[PR 11111](https://github.com/gradio-app/gradio/pull/11111)".If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.