File size: 1,306 Bytes
091117d
 
 
 
 
 
 
 
698a89d
091117d
 
 
 
 
 
 
698a89d
 
 
1d235a8
 
 
 
091117d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, UploadFile, File, Response,Header, BackgroundTasks,Body
from fastapi.staticfiles import StaticFiles
from vitpose import VitPose
import os 
from dotenv import load_dotenv
from tasks import process_video
from fastapi.responses import JSONResponse
from config import API_KEY
app = FastAPI()
vitpose = VitPose()
# vitpose.pipeline.warmup()

load_dotenv()


app.mount("/static", StaticFiles())

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

@app.get("/test")
def test():
    return {"message": "from test"}

@app.post("/upload")
async def upload(background_tasks: BackgroundTasks,
                 file: UploadFile = File(...), 
                 token: str = Header(...),
                 user_id: str = Body(...)):
    
    if token != API_KEY:
        return JSONResponse(content={"message": "Unauthorized", "status": 401})
    
    contents = await file.read()
    # Save the file to the local directory  
    with open(file.filename, "wb") as f:
        f.write(contents)
    

    
    # Create a clone of the file with content already read
    background_tasks.add_task(process_video, file.filename, vitpose, user_id)  

    # Return the file as a response
    return JSONResponse(content={"message": "Video uploaded successfully", "status": 200})