Skip to content

Commit

Permalink
๐ŸŒ [i18n-KO] Translated guides/webhooks_server.md to Korean (#2145)
Browse files Browse the repository at this point in the history
* docs: ko: guides/webhooks_server.md

* feat: nmt draft

* fix: manual edits

* fix: resolve suggestions

Co-authored-by: ๊น€์ค€์žฌ <55151385+junejae@users.noreply.github.com>
Co-authored-by: Harheem Kim <49297157+harheem@users.noreply.github.com>

---------

Co-authored-by: ๊น€์ค€์žฌ <55151385+junejae@users.noreply.github.com>
Co-authored-by: Harheem Kim <49297157+harheem@users.noreply.github.com>
Co-authored-by: Lucain <lucainp@gmail.com>
  • Loading branch information
4 people authored Apr 18, 2024
1 parent c28d154 commit 8f5795a
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/source/ko/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
title: (๋ฒˆ์—ญ ์ค‘) Manage your Space
- local: in_translation
title: (๋ฒˆ์—ญ ์ค‘) Integrate a library
- local: in_translation
title: (๋ฒˆ์—ญ ์ค‘) Webhooks server
- local: guides/webhooks_server
title: ์›นํ›… ์„œ๋ฒ„
- title: "(๋ฒˆ์—ญ ์ค‘) ๊ฐœ๋… ๊ฐ€์ด๋“œ"
sections:
- local: concepts/git_vs_http
Expand Down
199 changes: 199 additions & 0 deletions docs/source/ko/guides/webhooks_server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<!--โš ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->

# ์›นํ›… ์„œ๋ฒ„[[webhooks-server]]

์›นํ›…์€ MLOps ๊ด€๋ จ ๊ธฐ๋Šฅ์˜ ๊ธฐ๋ฐ˜์ด ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ํŠน์ • ์ €์žฅ์†Œ์˜ ์ƒˆ๋กœ์šด ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ˆ˜์‹ ํ•˜๊ฑฐ๋‚˜,
๊ด€์‹ฌ ์žˆ๋Š” ํŠน์ • ์‚ฌ์šฉ์ž/์กฐ์ง์— ์†ํ•œ ๋ชจ๋“  ์ €์žฅ์†Œ์˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฐ›์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๊ฐ€์ด๋“œ์—์„œ๋Š” `huggingface_hub`๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์›นํ›…์„ ์ˆ˜์‹ ํ•˜๋Š” ์„œ๋ฒ„๋ฅผ ๋งŒ๋“ค๊ณ  Space์— ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” Huggingface Hub์˜ ์›นํ›… ๊ฐœ๋…์— ๋Œ€ํ•ด ์ต์ˆ™ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์›นํ›… ์ž์ฒด์— ๋Œ€ํ•ด ๋” ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ์ด [๊ฐ€์ด๋“œ](https://huggingface.co/docs/hub/webhooks)๋ฅผ ๋จผ์ € ์ฝ์–ด๋ณด์„ธ์š”.

์ด ๊ฐ€์ด๋“œ์—์„œ ์‚ฌ์šฉํ•  ๊ธฐ๋ณธ ํด๋ž˜์Šค๋Š” [`WebhooksServer`]์ž…๋‹ˆ๋‹ค.
์ด ํด๋ž˜์Šค๋Š” Huggingface Hub์—์„œ ์›นํ›…์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์„œ๋ฒ„๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„œ๋ฒ„๋Š” [Gradio](https://gradio.app/) ์•ฑ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.
์ด ์„œ๋ฒ„์—๋Š” ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•œ ์ง€์นจ์„ ํ‘œ์‹œํ•˜๋Š” UI์™€ ์›นํ›…์„ ์ˆ˜์‹ ํ•˜๋Š” API๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

<Tip>

์›นํ›… ์„œ๋ฒ„์˜ ์‹คํ–‰ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ ค๋ฉด [Spaces CI Bot](https://huggingface.co/spaces/spaces-ci-bot/webhook)์„ ํ™•์ธํ•˜์„ธ์š”.
์ด๊ฒƒ์€ Space์˜ PR์ด ์—ด๋ฆด ๋•Œ๋งˆ๋‹ค ์ž„์‹œ ํ™˜๊ฒฝ์„ ์‹คํ–‰ํ•˜๋Š” Space์ž…๋‹ˆ๋‹ค.

</Tip>

<Tip warning={true}>

์ด๊ฒƒ์€ [์‹คํ—˜์  ๊ธฐ๋Šฅ](../package_reference/environment_variables#hfhubdisableexperimentalwarning)์ž…๋‹ˆ๋‹ค.
๋ณธ API๋Š” ํ˜„์žฌ ๊ฐœ์„  ์ž‘์—… ์ค‘์ด๋ฉฐ, ํ–ฅํ›„ ์‚ฌ์ „ ํ†ต์ง€ ์—†์ด ์ฃผ์š” ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ๋„์ž…๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
requirements์—์„œ `huggingface_hub`์˜ ๋ฒ„์ „์„ ๊ณ ์ •ํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

</Tip>


## ์—”๋“œํฌ์ธํŠธ ์ƒ์„ฑ[[create-an-endpoint]]

์›นํ›… ์—”๋“œํฌ์ธํŠธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์€ ํ•จ์ˆ˜์— ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋งŒํผ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค.
์ฃผ์š” ๊ฐœ๋…์„ ์„ค๋ช…ํ•˜๊ธฐ ์œ„ํ•ด ์ฒซ ๋ฒˆ์งธ ์˜ˆ์‹œ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

```python
# app.py
from huggingface_hub import webhook_endpoint, WebhookPayload

@webhook_endpoint
async def trigger_training(payload: WebhookPayload) -> None:
if payload.repo.type == "dataset" and payload.event.action == "update":
# ๋ฐ์ดํ„ฐ ์„ธํŠธ๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜๋ฉด ํ•™์Šต ์ž‘์—…์„ ํŠธ๋ฆฌ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
...
```

์ด ์ฝ”๋“œ ์Šค๋‹ˆํŽซ์„ `'app.py'`๋ผ๋Š” ํŒŒ์ผ์— ์ €์žฅํ•˜๊ณ  `'python app.py'`๋กœ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค:

```text
Webhook secret is not defined. This means your webhook endpoints will be open to everyone.
To add a secret, set `WEBHOOK_SECRET` as environment variable or pass it at initialization:
`app = WebhooksServer(webhook_secret='my_secret', ...)`
For more details about webhook secrets, please refer to https://huggingface.co/docs/hub/webhooks#webhook-secret.
Running on local URL: http://127.0.0.1:7860
Running on public URL: https://1fadb0f52d8bf825fc.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Webhooks are correctly setup and ready to use:
- POST https://1fadb0f52d8bf825fc.gradio.live/webhooks/trigger_training
Go to https://huggingface.co/settings/webhooks to setup your webhooks.
```

์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ์›นํ›… ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค! ์ •ํ™•ํžˆ ์–ด๋–ค ์ผ์ด ์ผ์–ด๋‚ฌ๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

1. [`webhook_endpoint`]๋กœ ํ•จ์ˆ˜์— ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ [`WebhooksServer`] ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ด ์„œ๋ฒ„๋Š” http://127.0.0.1:7860 ์—์„œ ์‹คํ–‰๋˜๋Š” Gradio ์•ฑ์ž…๋‹ˆ๋‹ค.
์ด URL์„ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์—ด๋ฉด ๋“ฑ๋ก๋œ ์›นํ›…์— ๋Œ€ํ•œ ์ง€์นจ์ด ์žˆ๋Š” ๋žœ๋”ฉ ํŽ˜์ด์ง€๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
2. Gradio ์•ฑ์€ ๋‚ด๋ถ€์ ์œผ๋กœ FastAPI ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด POST ๊ฒฝ๋กœ `/webhooks/trigger_training`์ด ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
์ด ๊ฒฝ๋กœ๋Š” ์›นํ›…์„ ์ˆ˜์‹ ํ•˜๊ณ  ํŠธ๋ฆฌ๊ฑฐ๋  ๋•Œ `trigger_training` ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
FastAPI๋Š” ์ž๋™์œผ๋กœ ํŽ˜์ด๋กœ๋“œ๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๊ณ  [`WebhookPayload`] ๊ฐ์ฒด๋กœ ํ•จ์ˆ˜์— ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
์ด `pydantic` ๊ฐ์ฒด์—๋Š” ์›นํ›…์„ ํŠธ๋ฆฌ๊ฑฐํ•œ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋ชจ๋“  ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
3. Gradio ์•ฑ์€ ์ธํ„ฐ๋„ท์—์„œ ์š”์ฒญ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ„ฐ๋„๋„ ์—ด์—ˆ์Šต๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ํฅ๋ฏธ๋กœ์šด ๋ถ€๋ถ„์œผ๋กœ, https://huggingface.co/settings/webhooks ์—์„œ ๋กœ์ปฌ ๋จธ์‹ ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ์›นํ›…์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๋ฅผ ํ†ตํ•ด ์›นํ›… ์„œ๋ฒ„๋ฅผ ๋””๋ฒ„๊น…ํ•˜๊ณ  Space์— ๋ฐฐํฌํ•˜๊ธฐ ์ „์— ๋น ๋ฅด๊ฒŒ ๋ฐ˜๋ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
4. ๋งˆ์ง€๋ง‰์œผ๋กœ ๋กœ๊ทธ์—๋Š” ์„œ๋ฒ„๊ฐ€ ํ˜„์žฌ ๋น„๋ฐ€๋กœ ๋ณดํ˜ธ๋˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ๋กœ์ปฌ ๋””๋ฒ„๊น…์—๋Š” ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š์ง€๋งŒ ๋‚˜์ค‘์— ๊ณ ๋ คํ•ด์•ผ ํ•  ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค.

<Tip warning={true}>

๊ธฐ๋ณธ์ ์œผ๋กœ ์„œ๋ฒ„๋Š” ์Šคํฌ๋ฆฝํŠธ ๋์—์„œ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.
์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์—์„œ ์‹คํ–‰ ์ค‘์ด๋ผ๋ฉด `decorated_function.run()`์„ ํ˜ธ์ถœํ•˜์—ฌ ์„œ๋ฒ„๋ฅผ ์ˆ˜๋™์œผ๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ณ ์œ ํ•œ ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๋Ÿฌ ์—”๋“œํฌ์ธํŠธ๊ฐ€ ์žˆ๋”๋ผ๋„ ์„œ๋ฒ„๋ฅผ ํ•œ ๋ฒˆ๋งŒ ์‹œ์ž‘ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

</Tip>


## ์›นํ›… ์„ค์ •ํ•˜๊ธฐ[[configure-a-webhook]]

์›นํ›… ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ, ์ด์ œ ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๊ธฐ ์œ„ํ•ด ์›นํ›…์„ ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
https://huggingface.co/settings/webhooks ๋กœ ์ด๋™ํ•˜์—ฌ "Add a new webhook"์„ ํด๋ฆญํ•˜๊ณ  ์›นํ›…์„ ๊ตฌ์„ฑํ•˜์„ธ์š”.
๋ชจ๋‹ˆํ„ฐ๋งํ•  ๋Œ€์ƒ ์ €์žฅ์†Œ์™€ ์›นํ›… URL `https://1fadb0f52d8bf825fc.gradio.live/webhooks/trigger_training`์„ ์„ค์ •ํ•˜์„ธ์š”.

<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/configure_webhook.png"/>
</div>

์ด๊ฑธ๋กœ ๋์ž…๋‹ˆ๋‹ค! ์ด์ œ ๋Œ€์ƒ ์ €์žฅ์†Œ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ์›นํ›…์„ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ์ปค๋ฐ‹ ํ‘ธ์‹œ๊ฐ€ ๊ทธ ๋ฐฉ๋ฒ•์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์›นํ›…์˜ Activity ํƒญ์—์„œ ํŠธ๋ฆฌ๊ฑฐ๋œ ์ด๋ฒคํŠธ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์ž‘๋™ํ•˜๋Š” ๊ตฌ์„ฑ์ด ์žˆ์œผ๋ฏ€๋กœ ํ…Œ์ŠคํŠธํ•˜๊ณ  ๋น ๋ฅด๊ฒŒ ๋ฐ˜๋ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜๊ณ  ์„œ๋ฒ„๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๋ฉด ๊ณต๊ฐœ URL์ด ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ•„์š”ํ•œ ๊ฒฝ์šฐ Hub์—์„œ ์›นํ›… ๊ตฌ์„ฑ์„ ์—…๋ฐ์ดํŠธํ•˜์„ธ์š”.

## Space์— ๋ฐฐํฌํ•˜๊ธฐ[[deploy-to-a-space]]

์ด์ œ ์ž‘๋™ํ•˜๋Š” ์›นํ›… ์„œ๋ฒ„๊ฐ€ ๋งˆ๋ จ๋˜์—ˆ์œผ๋ฏ€๋กœ, ๋‹ค์Œ ๋ชฉํ‘œ๋Š” ์ด๋ฅผ Space์— ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. https://huggingface.co/new-space ์— ๊ฐ€์„œ Space๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฆ„์„ ์ง€์ •ํ•˜๊ณ , Gradio SDK๋ฅผ ์„ ํƒํ•œ ๋‹ค์Œ "Create Space"๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ `app.py` ํŒŒ์ผ๋กœ Space์— ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
Space๊ฐ€ ์ž๋™์œผ๋กœ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค!
Space์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด [๊ฐ€์ด๋“œ](https://huggingface.co/docs/hub/spaces-overview)๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์›นํ›… ์„œ๋ฒ„๊ฐ€ ์ด์ œ ๊ณต๊ฐœ Space์—์„œ ์‹คํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋ณด์•ˆ์„ ์„ค์ •ํ•˜๊ณ  ์‹ถ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
Space ์„ค์ • > "Repository secrets" ์„น์…˜ > "Add a secret" ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. `WEBHOOK_SECRET` ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ์›ํ•˜๋Š” ๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
[Webhooks ์„ค์ •](https://huggingface.co/settings/webhooks)์œผ๋กœ ๋Œ์•„๊ฐ€์„œ ์›นํ›… ๊ตฌ์„ฑ์— ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
์ด์ œ ์˜ฌ๋ฐ”๋ฅธ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์žˆ๋Š” ์š”์ฒญ๋งŒ ์„œ๋ฒ„์—์„œ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ด๊ฒŒ ์ „๋ถ€์ž…๋‹ˆ๋‹ค! Space๊ฐ€ ์ด์ œ Hub์˜ ์›นํ›…์„ ์ˆ˜์‹ ํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๋ฌด๋ฃŒ ํ•˜๋“œ์›จ์–ด์ธ 'cpu-basic'์—์„œ Space๋ฅผ ์‹คํ–‰ ์‹œ, 48์‹œ๊ฐ„ ๋™์•ˆ ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด ์ข…๋ฃŒ๋œ๋‹ค๋Š” ์ ์„ ์œ ๋…ํ•˜์„ธ์š”.
์˜๊ตฌ์ ์ธ Space๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ [์—…๊ทธ๋ ˆ์ด๋“œ๋œ ํ•˜๋“œ์›จ์–ด](https://huggingface.co/docs/hub/spaces-gpus#hardware-specs)๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

## ๊ณ ๊ธ‰ ์‚ฌ์šฉ๋ฒ•[[advanced-usage]]

์œ„์˜ ๊ฐ€์ด๋“œ์—์„œ๋Š” [`WebhooksServer`]๋ฅผ ์„ค์ •ํ•˜๋Š” ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์„ค๋ช…ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ด ์„น์…˜์—์„œ๋Š” ์ด๋ฅผ ๋”์šฑ ์‚ฌ์šฉ์ž ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

### ๋‹ค์ค‘ ์—”๋“œํฌ์ธํŠธ[[multiple-endpoints]]

๋™์ผํ•œ ์„œ๋ฒ„์— ์—ฌ๋Ÿฌ ์—”๋“œํฌ์ธํŠธ๋ฅผ ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ํ•˜๋‚˜์˜ ์—”๋“œํฌ์ธํŠธ๋Š” ํ•™์Šต ์ž‘์—…์„ ํŠธ๋ฆฌ๊ฑฐํ•˜๊ณ  ๋‹ค๋ฅธ ์—”๋“œํฌ์ธํŠธ๋Š” ๋ชจ๋ธ ํ‰๊ฐ€๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๋ฅผ ์œ„ํ•ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ `@webhook_endpoint` ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค:

```python
# app.py
from huggingface_hub import webhook_endpoint, WebhookPayload

@webhook_endpoint
async def trigger_training(payload: WebhookPayload) -> None:
if payload.repo.type == "dataset" and payload.event.action == "update":
# ๋ฐ์ดํ„ฐ ์„ธํŠธ๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜๋ฉด ํ•™์Šต ์ž‘์—…์„ ํŠธ๋ฆฌ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
...

@webhook_endpoint
async def trigger_evaluation(payload: WebhookPayload) -> None:
if payload.repo.type == "model" and payload.event.action == "update":
# ๋ชจ๋ธ์ด ์—…๋ฐ์ดํŠธ๋˜๋ฉด ํ‰๊ฐ€ ์ž‘์—…์„ ํŠธ๋ฆฌ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
...
```

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋‘ ๊ฐœ์˜ ์—”๋“œํฌ์ธํŠธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค:

```text
(...)
Webhooks are correctly setup and ready to use:
- POST https://1fadb0f52d8bf825fc.gradio.live/webhooks/trigger_training
- POST https://1fadb0f52d8bf825fc.gradio.live/webhooks/trigger_evaluation
```

### ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋ฒ„[[custom-server]]

๋” ๋งŽ์€ ์œ ์—ฐ์„ฑ์„ ์–ป๊ธฐ ์œ„ํ•ด [`WebhooksServer`] ๊ฐ์ฒด๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ์„œ๋ฒ„์˜ ๋žœ๋”ฉ ํŽ˜์ด์ง€๋ฅผ ์‚ฌ์šฉ์ž ์ •์˜ํ•˜๊ณ ์ž ํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
๊ธฐ๋ณธ ํŽ˜์ด์ง€๋ฅผ ๋ฎ์–ด์“ธ [Gradio UI](https://gradio.app/docs/#blocks)๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ์ด๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•œ ์ง€์นจ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์›นํ›…์„ ์ˆ˜๋™์œผ๋กœ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š” ์–‘์‹์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
[`WebhooksServer`]๋ฅผ ์ƒ์„ฑํ•  ๋•Œ, [`~WebhooksServer.add_webhook`] ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒˆ๋กœ์šด ์›นํ›…์„ ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ „์ฒด ์˜ˆ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

```python
import gradio as gr
from fastapi import Request
from huggingface_hub import WebhooksServer, WebhookPayload

# 1. UI ์ •์˜
with gr.Blocks() as ui:
...

# 2. ์‚ฌ์šฉ์ž ์ •์˜ UI์™€ ์‹œํฌ๋ฆฟ์œผ๋กœ WebhooksServer ์ƒ์„ฑ
app = WebhooksServer(ui=ui, webhook_secret="my_secret_key")

# 3. ๋ช…์‹œ์  ์ด๋ฆ„์œผ๋กœ ์›นํ›… ๋“ฑ๋ก
@app.add_webhook("/say_hello")
async def hello(payload: WebhookPayload):
return {"message": "hello"}

# 4. ์•”์‹œ์  ์ด๋ฆ„์œผ๋กœ ์›นํ›… ๋“ฑ๋ก
@app.add_webhook
async def goodbye(payload: WebhookPayload):
return {"message": "goodbye"}

# 5. ์„œ๋ฒ„ ์‹œ์ž‘ (์„ ํƒ ์‚ฌํ•ญ)
app.run()
```

1. Gradio ๋ธ”๋ก์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ •์˜ UI๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์ด UI๋Š” ์„œ๋ฒ„์˜ ๋žœ๋”ฉ ํŽ˜์ด์ง€์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
2. ์‚ฌ์šฉ์ž ์ •์˜ UI์™€ ์‹œํฌ๋ฆฟ์œผ๋กœ [`WebhooksServer`] ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์‹œํฌ๋ฆฟ์€ ์„ ํƒ ์‚ฌํ•ญ์ด๋ฉฐ `WEBHOOK_SECRET` ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
3. ๋ช…์‹œ์  ์ด๋ฆ„์œผ๋กœ ์›นํ›…์„ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `/webhooks/say_hello` ์—”๋“œํฌ์ธํŠธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
4. ์•”์‹œ์  ์ด๋ฆ„์œผ๋กœ ์›นํ›…์„ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `/webhooks/goodbye` ์—”๋“œํฌ์ธํŠธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
5. ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์„ ํƒ ์‚ฌํ•ญ์ด๋ฉฐ ์Šคํฌ๋ฆฝํŠธ ๋์—์„œ ์ž๋™์œผ๋กœ ์„œ๋ฒ„๊ฐ€ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.

0 comments on commit 8f5795a

Please sign in to comment.