-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
133 lines (78 loc) · 2.93 KB
/
tasks.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import types
from celery.app.base import App
import views
from celery import Celery
from app import db
from function.clova_func import *
from celery.utils.log import get_task_logger
from function.trans import *
import time
import function.video_func
import requests
import asyncio
from app import simple_tasks
logger = get_task_logger(__name__)
@simple_tasks.task()
def async_download_video(youtube_url, file_number):
return function.video_func.download_video(youtube_url, file_number)
@simple_tasks.task()
def post_toYolo(pk, video_path):
data = {'video_pk': pk, 's3_video': video_path}
return requests.post('http://0.0.0.0:5001/to_yolo', json=data).content
@simple_tasks.task()
def sendto_yolo(video_path, video_pk):
logger.info('Got Request - Starting work ')
data = {"video_path": video_path, "video_pk": video_pk}
requests.post('http://backend_model:5050/to_yolo', json=data, verify=False)
logger.info('Work Finished ')
pass
@simple_tasks.task()
def run_clova(video_pk, audio_path, lang):
post_result = clova(audio_path, lang)
save_audio_result_to_mongo(video_pk, post_result)
pass
#===============================================================================================
#여기부턴 asynd 함수
from app import coll
@types.coroutine
def switch():
yield
def save_audio_result_to_mongo(video_pk, post_result):
coll.insert({
'video_number': video_pk,
'sentence_list': post_result['sentence_list']
})
def clova(audio_path, lang):
pre_result = ClovaSpeechClient().req_url(url=audio_path, language = lang, completion='sync')
post_result = to_json(pre_result)
return post_result
async def send_to_yolo(video_path, video_pk):
data = {"video_path": video_path, "video_pk": video_pk}
requests.post('http://backend_model:5050/to_yolo', json=data, verify=False)
logger.info('Work Finished ')
async def detect_start(video_pk, audio_path, video_path, lang):
await asyncio.gather(asyncio.create_task(send_to_yolo(video_path, video_pk)), asyncio.create_task(run_clova(video_pk, audio_path, lang)))
async def run_yolo(video_path, video_pk):
await send_to_yolo(video_path, video_pk)
async def detect_clovd(video_pk, audio_path, lang):
await run_clova(video_pk, audio_path, lang)
async def detect_yolo(video_path, video_pk):
await send_to_yolo(video_path, video_pk)
# try:
# await run_yolo(video_path, video_pk)
# yolo_result = True
# except:
# yolo_result = False
# try:
# await run_clova(video_pk, audio_path, lang)
# clova_result = True
# except:
# clova_result = False
# return yolo_result, clova_result
# @task_postrun.connect
# def close_session(*args, **kwargs):
# db.session.remove()
# start celery worker
# celery -A tasks worker --loglevel=info
# start celery beat
# celery -A tasks.celery beat --loglevel=info