nicolasbuitragob commited on
Commit
5093bc2
·
1 Parent(s): 3416102
Files changed (2) hide show
  1. tasks.py +9 -1
  2. vitpose.py +8 -1
tasks.py CHANGED
@@ -4,8 +4,13 @@ import os
4
  from fastapi import UploadFile
5
  from config import API_URL
6
  import time
 
 
 
7
 
8
  def process_video(video_path: str,vitpose: VitPose,user_id: str):
 
 
9
 
10
  new_file_name = video_path.split(".")[0] + "edited." + video_path.split(".")[1]
11
  new_file_name = os.path.join("static", new_file_name)
@@ -14,13 +19,16 @@ def process_video(video_path: str,vitpose: VitPose,user_id: str):
14
  annotated_frames = vitpose.run(video_path)
15
  annotated_video_path = vitpose.frames_to_video(annotated_frames,rotate=True)
16
 
 
 
17
  with open(annotated_video_path, "rb") as f:
18
  contents = f.read()
19
 
20
  url = API_URL+ "/excercises/webhooks/video-processed"
21
-
22
  files = {"file": (annotated_video_path, contents, "video/mp4")}
23
  response = requests.post(url, files=files, data={"user_id":user_id,"typeMessage":"video_processed","file_name":annotated_video_path}, stream=True)
 
24
  print(response.json())
25
  os.remove(video_path)
26
  os.remove(annotated_video_path)
 
4
  from fastapi import UploadFile
5
  from config import API_URL
6
  import time
7
+ import logging
8
+ logging.basicConfig(level=logging.INFO)
9
+ logger = logging.getLogger(__name__)
10
 
11
  def process_video(video_path: str,vitpose: VitPose,user_id: str):
12
+
13
+ logger.info(f"Processing video {video_path}")
14
 
15
  new_file_name = video_path.split(".")[0] + "edited." + video_path.split(".")[1]
16
  new_file_name = os.path.join("static", new_file_name)
 
19
  annotated_frames = vitpose.run(video_path)
20
  annotated_video_path = vitpose.frames_to_video(annotated_frames,rotate=True)
21
 
22
+ logger.info(f"Video processed {annotated_video_path}")
23
+
24
  with open(annotated_video_path, "rb") as f:
25
  contents = f.read()
26
 
27
  url = API_URL+ "/excercises/webhooks/video-processed"
28
+ logger.info(f"Sending video to {url}")
29
  files = {"file": (annotated_video_path, contents, "video/mp4")}
30
  response = requests.post(url, files=files, data={"user_id":user_id,"typeMessage":"video_processed","file_name":annotated_video_path}, stream=True)
31
+ logger.info(f"Video sent to {url}")
32
  print(response.json())
33
  os.remove(video_path)
34
  os.remove(annotated_video_path)
vitpose.py CHANGED
@@ -5,6 +5,11 @@ import supervision as sv
5
  import numpy as np
6
  from rt_pose import PoseEstimationPipeline, PoseEstimationOutput
7
 
 
 
 
 
 
8
 
9
  class VitPose:
10
  def __init__(self):
@@ -38,10 +43,12 @@ class VitPose:
38
  def run(self,video):
39
  frames = self.video_to_frames(video)
40
  annotated_frames = []
41
- for frame in frames:
 
42
  output = self.pipeline(frame)
43
  annotated_frame = self.visualize_output(frame,output)
44
  annotated_frames.append(annotated_frame)
 
45
  return annotated_frames
46
 
47
 
 
5
  import numpy as np
6
  from rt_pose import PoseEstimationPipeline, PoseEstimationOutput
7
 
8
+ import logging
9
+
10
+ logging.basicConfig(level=logging.INFO)
11
+ logger = logging.getLogger(__name__)
12
+
13
 
14
  class VitPose:
15
  def __init__(self):
 
43
  def run(self,video):
44
  frames = self.video_to_frames(video)
45
  annotated_frames = []
46
+ for i, frame in enumerate(frames):
47
+ logger.info(f"Processing frame {i} of {len(frames)}")
48
  output = self.pipeline(frame)
49
  annotated_frame = self.visualize_output(frame,output)
50
  annotated_frames.append(annotated_frame)
51
+ logger.info(f"Processed {len(annotated_frames)} frames")
52
  return annotated_frames
53
 
54