Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import WebhooksServer, WebhookPayload
|
| 4 |
+
|
| 5 |
+
# Optional: custom UI for your Space landing page
|
| 6 |
+
with gr.Blocks() as ui:
|
| 7 |
+
gr.Markdown("# 🛠️ MCP-Webhooks-CodeFix Webhook Receiver")
|
| 8 |
+
gr.Markdown(
|
| 9 |
+
"This Space listens to Hugging Face Hub webhooks and displays the incoming payloads."
|
| 10 |
+
)
|
| 11 |
+
gr.Markdown("🎯 Set up a webhook in your Hugging Face account to point here.")
|
| 12 |
+
|
| 13 |
+
# Read secret from env or define directly
|
| 14 |
+
webhook_secret = os.getenv("WEBHOOK_SECRET", None)
|
| 15 |
+
|
| 16 |
+
# Launch the webhook server with optional security
|
| 17 |
+
app = WebhooksServer(ui=ui, webhook_secret=webhook_secret)
|
| 18 |
+
|
| 19 |
+
@app.add_webhook("/on_push")
|
| 20 |
+
async def on_repository_push(payload: WebhookPayload):
|
| 21 |
+
# Example: handle repo pushes
|
| 22 |
+
repo_name = payload.repo.name
|
| 23 |
+
event = payload.event.action
|
| 24 |
+
return {"msg": f"Received {event} in repo `{repo_name}`"}
|
| 25 |
+
|
| 26 |
+
@app.add_webhook("/on_discussion")
|
| 27 |
+
async def on_discussion_event(payload: WebhookPayload):
|
| 28 |
+
# Example: handle discussion events
|
| 29 |
+
discussion = payload.discussion
|
| 30 |
+
title = discussion.title if discussion else "N/A"
|
| 31 |
+
return {"msg": f"Discussion event on '{title}'"}
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
# Starts the Gradio / FastAPI app with webhook endpoints
|
| 35 |
+
app.launch()
|