File size: 874 Bytes
08d7436
 
 
 
 
be7bb76
08d7436
711adee
08d7436
711adee
08d7436
 
 
 
 
 
 
711adee
08d7436
 
 
 
 
 
 
 
 
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("KEY")

main = FastAPI()

@main.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")

@main.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