Spaces:
Sleeping
Sleeping
File size: 882 Bytes
a0de473 66a9456 a0de473 c376098 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import os
from fastapi import FastAPI, Request, Response
from main import create_or_update_report
from tabulate import tabulate
KEY = os.environ.get("WEBHOOK_SECRET")
app = FastAPI()
@app.get("/")
def read_root():
data = """
<h2 style="text-align:center">Metadata Review Bot</h2>
<p style="text-align:center">This is a demo app showing how to use webhooks to automate metadata review for models and datasets shared on the Hugging Face Hub.</p>
"""
return Response(content=data, media_type="text/html")
@app.post("/webhook")
async def webhook(request: Request):
if request.method == "POST":
if request.headers.get("X-Webhook-Secret") != KEY:
return Response("Invalid secret", status_code=401)
data = await request.json()
result = create_or_update_report(data)
return "Webhook received!" if result else result
|