import gradio as gr import os from huggingface_hub import WebhooksServer, WebhookPayload # Optional: custom UI for your Space landing page with gr.Blocks() as ui: gr.Markdown("# 🛠️ MCP-Webhooks-CodeFix Webhook Receiver") gr.Markdown( "This Space listens to Hugging Face Hub webhooks and displays the incoming payloads." ) gr.Markdown("🎯 Set up a webhook in your Hugging Face account to point here.") # Read secret from env or define directly webhook_secret = os.getenv("WEBHOOK_SECRET", None) # Launch the webhook server with optional security app = WebhooksServer(ui=ui, webhook_secret=webhook_secret) @app.add_webhook("/on_push") async def on_repository_push(payload: WebhookPayload): # Example: handle repo pushes repo_name = payload.repo.name event = payload.event.action return {"msg": f"Received {event} in repo `{repo_name}`"} @app.add_webhook("/on_discussion") async def on_discussion_event(payload: WebhookPayload): # Example: handle discussion events discussion = payload.discussion title = discussion.title if discussion else "N/A" return {"msg": f"Discussion event on '{title}'"} if __name__ == "__main__": # Starts the Gradio / FastAPI app with webhook endpoints app.launch()