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 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}