SportsAI / tasks.py
nicolasbuitragob's picture
edits
9085b9a
raw
history blame
1.32 kB
from vitpose import VitPose
import requests
import os
from fastapi import UploadFile
from config import API_URL
import time
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def process_video(video_path: str,vitpose: VitPose,user_id: str):
logger.info(f"starting task {video_path}")
new_file_name = video_path.split(".")[0] + "edited." + video_path.split(".")[1]
new_file_name = os.path.join("static", new_file_name)
logger.info(f"new file name {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)
logger.info(f"Video processed {annotated_video_path}")
with open(annotated_video_path, "rb") as f:
contents = f.read()
url = API_URL+ "/excercises/webhooks/video-processed"
logger.info(f"Sending video to {url}")
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)
logger.info(f"Video sent to {url}")
print(response.json())
# os.remove(video_path)
# os.remove(annotated_video_path)