simonl0909's picture
global keyword
ceb3cb1
raw
history blame contribute delete
764 Bytes
import gradio as gr
from huggingface_hub import WebhooksServer, WebhookPayload
# from model import model
webhook_payload = None
with gr.Blocks() as ui:
p = gr.State(None)
def update_payload():
return webhook_payload.json() if webhook_payload is not None else ''
gr.Markdown(f"## Hugging Face Webhooks Demo\n\n{p.value}")
progress = gr.Progress(track_tqdm=True)
ui.load(update_payload, outputs=[p])
# 2. Create WebhooksServer with custom UI and secret
app = WebhooksServer(ui=ui, webhook_secret="test")
@app.add_webhook
async def train(payload: WebhookPayload):
global webhook_payload
webhook_payload = payload
print("Received payload:", payload.dict())
return payload.dict()
# 5. Start server (optional)
app.run()