SportsAI / tasks.py
nicolasRolebot's picture
webhooks and background task
091117d
raw
history blame
982 Bytes
from vitpose import VitPose
import requests
import os
from fastapi import UploadFile
from config import API_URL
import time
def process_video(video_path: str,vitpose: VitPose,user_id: str):
new_file_name = video_path.split(".")[0] + "edited." + video_path.split(".")[1]
new_file_name = os.path.join("static", new_file_name)
vitpose.output_video_path = new_file_name
annotated_frames = vitpose.run(video_path)
annotated_video_path = vitpose.frames_to_video(annotated_frames,rotate=True)
with open(annotated_video_path, "rb") as f:
contents = f.read()
url = API_URL+ "/excercises/webhooks/video-processed"
files = {"file": (annotated_video_path, contents, "video/mp4")}
response = requests.post(url, files=files, data={"user_id":user_id,"typeMessage":"video_processed","file_name":annotated_video_path}, stream=True)
print(response.json())
os.remove(video_path)
os.remove(annotated_video_path)