phuochungus commited on
Commit
810208f
1 Parent(s): 935880c
app/routers/video.py CHANGED
@@ -21,6 +21,7 @@ from app import supabase
21
  from app.dependencies import get_current_user
22
  from app.routers.image import inferenceImage
23
  from google.cloud.firestore_v1.base_query import FieldFilter
 
24
 
25
  router = APIRouter(prefix="/video", tags=["Video"])
26
 
@@ -54,20 +55,22 @@ async def handleVideoRequest(
54
  background_tasks.add_task(inferenceVideo, artifact_ref.id, id, threshold)
55
  return id + ".mp4"
56
  except ValueError as err:
57
- print(err)
58
- print("Error processing video")
59
  shutil.rmtree(id)
60
 
61
 
62
  def now():
63
  return round(time.time() * 1000)
64
 
 
65
  def createThumbnail(thumbnail, inputDir):
66
  thumbnail = cv2.resize(
67
  src=thumbnail, dsize=(160, 160), interpolation=cv2.INTER_AREA
68
  )
69
  cv2.imwrite(os.path.join(inputDir, "thumbnail.jpg"), thumbnail)
70
- def inference_frame(inputDir, threshold:float=0.3):
 
 
71
  cap = cv2.VideoCapture(
72
  filename=os.path.join(inputDir, "input.mp4"), apiPreference=cv2.CAP_FFMPEG
73
  )
@@ -101,11 +104,14 @@ def inference_frame(inputDir, threshold:float=0.3):
101
  del cap
102
  del result
103
  return thumbnail
 
 
104
  async def inferenceVideo(artifactId: str, inputDir: str, threshold: float):
105
  try:
106
  Process(updateArtifact(artifactId, {"status": "processing"})).start()
107
  thumbnail = inference_frame(inputDir, threshold=threshold)
108
  createThumbnail(thumbnail, inputDir)
 
109
  async def uploadVideo():
110
  async with aiofiles.open(os.path.join(inputDir, "out.mp4"), "rb") as f:
111
  supabase.storage.from_("video").upload(
 
21
  from app.dependencies import get_current_user
22
  from app.routers.image import inferenceImage
23
  from google.cloud.firestore_v1.base_query import FieldFilter
24
+ from app import logger
25
 
26
  router = APIRouter(prefix="/video", tags=["Video"])
27
 
 
55
  background_tasks.add_task(inferenceVideo, artifact_ref.id, id, threshold)
56
  return id + ".mp4"
57
  except ValueError as err:
58
+ logger.error(err)
 
59
  shutil.rmtree(id)
60
 
61
 
62
  def now():
63
  return round(time.time() * 1000)
64
 
65
+
66
  def createThumbnail(thumbnail, inputDir):
67
  thumbnail = cv2.resize(
68
  src=thumbnail, dsize=(160, 160), interpolation=cv2.INTER_AREA
69
  )
70
  cv2.imwrite(os.path.join(inputDir, "thumbnail.jpg"), thumbnail)
71
+
72
+
73
+ def inference_frame(inputDir, threshold: float = 0.3):
74
  cap = cv2.VideoCapture(
75
  filename=os.path.join(inputDir, "input.mp4"), apiPreference=cv2.CAP_FFMPEG
76
  )
 
104
  del cap
105
  del result
106
  return thumbnail
107
+
108
+
109
  async def inferenceVideo(artifactId: str, inputDir: str, threshold: float):
110
  try:
111
  Process(updateArtifact(artifactId, {"status": "processing"})).start()
112
  thumbnail = inference_frame(inputDir, threshold=threshold)
113
  createThumbnail(thumbnail, inputDir)
114
+
115
  async def uploadVideo():
116
  async with aiofiles.open(os.path.join(inputDir, "out.mp4"), "rb") as f:
117
  supabase.storage.from_("video").upload(
worker/__init__.py → app/worker/__init_.py RENAMED
File without changes
app/worker/celery.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from celery import Celery
2
+
3
+ app = Celery("worker", broker="redis://localhost:6379", include=["worker.tasks"])
4
+
5
+ if __name__ == "__main__":
6
+ app.start()
app/worker/tasks.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from .celery import app
2
+
3
+
4
+ @app.task
5
+ def add(x, y):
6
+ return x + y
worker/main.py DELETED
File without changes