Wauplin HF staff commited on
Commit
e7d09e5
1 Parent(s): 6873536
Files changed (2) hide show
  1. README.md +49 -1
  2. gradio_webhooks.py +1 -1
README.md CHANGED
@@ -11,4 +11,52 @@ pinned: false
11
 
12
  ## Spaces CI webhook
13
 
14
- This is a webhook space to build temporary Spaces when a PR is submitted.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  ## Spaces CI webhook
13
 
14
+ This is a webhook space to build temporary Spaces when a PR is submitted.
15
+
16
+ ## gradio_webhooks
17
+
18
+ This is also a PoC for a `gradio_webhooks` helper library. It uses Gradio to launch a server and register webhooks on it.
19
+
20
+ The major goal is to make the development process as easy as possible:
21
+ - debug your webhooks locally using a Gradio URL
22
+ - push your webhook server to a Gradio Space once ready
23
+
24
+ Features:
25
+ - Server app with `GradioWebhookApp`
26
+ - Debug locally before deploying on Spaces
27
+ - Handle `x-webhook-secret` header
28
+ - Output is parsed as `WebhookPayload` (to be completed)
29
+
30
+ ### Quick example:
31
+
32
+ **app.py**
33
+
34
+ ```py
35
+ from gradio_webhooks import GradioWebhookApp, WebhookPayload
36
+
37
+ app = GradioWebhookApp(webhook_secret="my_dummy_secret")
38
+
39
+
40
+ @app.add_webhook("/my_webhook")
41
+ async def hello(payload: WebhookPayload):
42
+ print(f"Received webhook for repo {payload.repo.name}")
43
+ return {"processed": True}
44
+
45
+
46
+ app.ready()
47
+ ```
48
+
49
+ **Output in terminal**
50
+
51
+ ```text
52
+ Running on local URL: http://127.0.0.1:7860
53
+ Running on public URL: https://18ffc05a-d0bf-4041.gradio.live
54
+
55
+ This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
56
+
57
+ Webhook secret is correctly defined.
58
+
59
+ Webhooks are correctly setup and ready to use:
60
+ - POST https://18ffc05a-d0bf-4041.gradio.live/my_webhook
61
+ Go to https://huggingface.co/settings/webhooks to setup your webhooks.
62
+ ```
gradio_webhooks.py CHANGED
@@ -80,7 +80,7 @@ class GradioWebhookApp:
80
  ).strip("/")
81
  print("\nWebhooks are correctly setup and ready to use:")
82
  print("\n".join(f" - POST {url}{webhook}" for webhook in self.webhook_paths))
83
- print(f"Checkout {url}/docs for more details.")
84
  self.gradio_app.block_thread()
85
 
86
  async def _webhook_secret_middleware(self, request: Request, call_next) -> None:
 
80
  ).strip("/")
81
  print("\nWebhooks are correctly setup and ready to use:")
82
  print("\n".join(f" - POST {url}{webhook}" for webhook in self.webhook_paths))
83
+ print("Go to https://huggingface.co/settings/webhooks to setup your webhooks.")
84
  self.gradio_app.block_thread()
85
 
86
  async def _webhook_secret_middleware(self, request: Request, call_next) -> None: