File size: 1,775 Bytes
b9721b4
 
 
 
066f361
b9721b4
51e9b93
 
 
23b4bde
 
 
de969c6
b9721b4
51e9b93
 
ba0c441
23b4bde
b9721b4
 
51e9b93
 
b9721b4
55af089
 
 
 
 
 
51e9b93
 
 
 
 
4401500
51e9b93
7cb6878
51e9b93
 
 
 
4401500
 
51e9b93
 
 
dd82ecb
 
4401500
 
51e9b93
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import requests
from typing import Optional
from huggingface_hub import snapshot_download
from fastapi import FastAPI, Header, HTTPException, Request, Response
from huggingface_hub.hf_api import HfApi
from huggingface_hub import whoami
from huggingface_hub.utils import build_hf_headers, hf_raise_for_status
from huggingface_hub import delete_repo

app = FastAPI()

api = HfApi() 

token = "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"

@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()
        if(data["event"]["action"]=="update" and data["event"]["scope"]=="repo.content" and data["repo"]["type"]=="model"):
            try:
                _ = whoami(token)
                # ^ this will throw if token is invalid
    
                delete_repo(repo_id="shellplc/ThirdParty", token = token, repo_type="model",missing_ok=True)
                print("deleted")
                r = requests.post(
                    f"https://huggingface.co/api/models/SakethTest/ThirdParty/duplicate",
                    headers=build_hf_headers(token=token),
                    json={"repository": "shellplc/ThirdParty"},
                )
                hf_raise_for_status(r)
                repo_url = r.json().get("url")
                print(repo_url)
                return {"processed": True}
                
            except Exception as e:
                print("its exception")
                print(e)
        else:
            print("cond didn't match")
    return {"processed": False}