-
Notifications
You must be signed in to change notification settings - Fork 608
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
[Feat] Webhook server #1410
[Feat] Webhook server #1410
Conversation
The documentation is not available anymore as the PR was closed or merged. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1410 +/- ##
==========================================
- Coverage 84.39% 84.34% -0.05%
==========================================
Files 49 52 +3
Lines 5254 5430 +176
==========================================
+ Hits 4434 4580 +146
- Misses 820 850 +30
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
took only a very superficial glance, but looks cool
also cc @coyotte508 for webhooks context
My only suggestion is maybe rename @as_webhook_endpoint
to just the simpler @webhook_endpoint
Very cool! |
@coyotte508 thanks for letting me know. I added the |
# Start Gradio App | ||
# - as non-blocking so that webhooks can be added afterwards | ||
# - as shared if launch locally (to debug webhooks) | ||
self.fastapi_app, _, _ = ui.launch(prevent_thread_lock=True, share=_is_local) |
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.
You can create the fastapi app used by gradio without launching the server.
app = gr.routes.App.create_app(self.ui)
I think that will make it easier to check the webhook secret via a middleware.
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.
Actually, I don't think this will work as calling launch
after adding the middleware will recreate the FastAPI app and remove the middleware
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.
I'm not using a middleware at all in the end. The add_middleware
stuff was legacy code I didn't removed.
Good to know about the gr.routes.App.create_app
possibility! But as you said I need the .launch()
call afterwards so I'll not use it here.
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.
Awesome PR @Wauplin. Tested and works great and the gradio usage is sound!
# Start Gradio App | ||
# - as non-blocking so that webhooks can be added afterwards | ||
# - as shared if launch locally (to debug webhooks) | ||
self.fastapi_app, _, _ = ui.launch(prevent_thread_lock=True, share=_is_local) |
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.
Actually, I don't think this will work as calling launch
after adding the middleware will recreate the FastAPI app and remove the middleware
Thanks for reviewing @freddyaboulton! It was useful after all 😄 Glad you tested it as well 👍 |
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.
Really nice work! 👏
Super detailed docstrings, in fact, I think the docstrings may be a bit overloaded with information 😅 and some of it would be fantastic in a how-to guide. I feel like here, users are learning about Webhooks for the first time instead of using the reference as a description of what a parameter does.
Thanks for the feedback @stevhliu !
Yes, I hesitated to do a guide but felt that it would be too short. In the end I followed your advice and created this step-by-step guide. It takes major parts of the dostrings + adds a few explanations on how to deploy that to a Space. |
I'm finally merging it! :) Thanks to everyone involved 🙏 |
This PR adds a new
WebhookServer
object to create and run a server that can handle HF Webhooks. Is it based on top of Gradio and FastAPI. The main goal is to ease setting up a Space to handle webhooks.Initially started the discussion on slack (internal link) cc @abidlabs @freddyaboulton @davanstrien @merveenoyan who showed some interest back in February. Please let me know if you have any feedback (design-wise, API-wise, doc-wise,...)
@LysandreJik @julien-c @osanseviero Most of the code/content is already written but before a thorough review I think it's best to wait for a high-level feedback :)
Main features:
webhook_secret
(orWEBHOOK_SECRET
environment variable)Examples:
@webhook_endpoint
=> server is automatically startedor
WebhookServer
for more flexibility (custom secret/ui)TODO: