File size: 1,118 Bytes
b9721b4
 
 
 
 
 
 
23b4bde
 
 
de969c6
b9721b4
ba0c441
23b4bde
b9721b4
 
 
55af089
 
 
 
 
 
 
 
 
 
 
 
b9721b4
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
29
30
31
import os
import requests
from typing import Optional
from huggingface_hub import snapshot_download
from fastapi import FastAPI, Header, HTTPException, BackgroundTasks
from huggingface_hub.hf_api import HfApi


app = FastAPI()

api = HfApi() 

@app.get("/")
def read_root():
    return {"Hello": "World!"}

@app.post("/webhook")
async def webhook(request: Request):
    if request.method == "POST":
        if request.headers.get("X-Webhook-Secret") != "webhooksecret":
            return Response("Invalid secret", status_code=401)
        data = await request.json()
        result = create_or_update_report(data)
        if(data["event"]["action"]=="update" and data["event"]["scope"]=="repo.content" and data["repo"]["type"]=="model"):
            snapshot_download(repo_id="SakethTest/ThirdParty",local_dir="./ThirdParty")
            api.upload_folder(folder_path="./ThirdParty",repo_id="shellplc/ThirdParty",repo_type="model",commit_message="uploaded third party model",token="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")
            return {"processed": True}
        else:
            return {"processed": False}