rogerxavier
commited on
Commit
•
fdf65e3
1
Parent(s):
02f726e
Update api.py
Browse files
api.py
CHANGED
@@ -101,40 +101,40 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
|
|
101 |
|
102 |
|
103 |
|
104 |
-
|
105 |
# @app.get("/execute_all_task")
|
106 |
-
# async def execute_all_task(background_tasks: BackgroundTasks,file_list: list = ["1removeMask", "2magiDialogCut", "3mergeDialogToVideo"],
|
107 |
-
# bili_meta_data:dict = None,cover_image: UploadFile = File(...),mp4_out_file:str='mp4_out/output.mp4',
|
108 |
-
# allow_submit:bool=False,cover_path:str ='/cover'
|
109 |
-
|
110 |
-
#
|
|
|
111 |
# for file_name in file_list:
|
112 |
-
#
|
|
|
|
|
|
|
113 |
# if allow_submit:
|
114 |
-
# #如果请求中设置允许上传output.mp4
|
115 |
# cover_img = cover_image.file.read()
|
116 |
# cover_img_data = Image.open(io.BytesIO(cover_img)).convert("L").convert("RGB")
|
117 |
# cover_path_to_image = os.path.join(cover_path, f"cover.jpg")
|
118 |
# cover_img_data.save(cover_path_to_image)
|
119 |
-
#
|
120 |
-
# background_tasks.add_task(upload_video, bili_meta_data,cover_path_to_image)
|
121 |
# return {"message": "提交video任务已加入队列"}
|
122 |
-
|
123 |
-
# return {"message": "Tasks added to the queue"}
|
124 |
|
|
|
125 |
|
126 |
-
#保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
|
127 |
@app.get("/execute_all_task")
|
128 |
-
async def execute_all_task(background_tasks: BackgroundTasks, file_list:
|
129 |
bili_meta_data: dict = None, cover_image: UploadFile = File(...), mp4_out_file: str = 'mp4_out/output.mp4',
|
130 |
allow_submit: bool = False, cover_path: str = '/cover'
|
131 |
):
|
132 |
-
print("获取到file_list是:",file_list)
|
133 |
tasks = []
|
134 |
for file_name in file_list:
|
135 |
tasks.append(file_executer(file_name))
|
136 |
|
137 |
-
await asyncio.gather(*tasks)
|
138 |
|
139 |
if allow_submit:
|
140 |
cover_img = cover_image.file.read()
|
@@ -152,6 +152,7 @@ async def execute_all_task(background_tasks: BackgroundTasks, file_list: list =
|
|
152 |
|
153 |
|
154 |
|
|
|
155 |
##########异步样例
|
156 |
def someTask():
|
157 |
time.sleep(20)
|
|
|
101 |
|
102 |
|
103 |
|
104 |
+
#保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
|
105 |
# @app.get("/execute_all_task")
|
106 |
+
# async def execute_all_task(background_tasks: BackgroundTasks, file_list: list = ["1removeMask", "2magiDialogCut", "3mergeDialogToVideo"],
|
107 |
+
# bili_meta_data: dict = None, cover_image: UploadFile = File(...), mp4_out_file: str = 'mp4_out/output.mp4',
|
108 |
+
# allow_submit: bool = False, cover_path: str = '/cover'
|
109 |
+
# ):
|
110 |
+
# print("获取到file_list是:",file_list)
|
111 |
+
# tasks = []
|
112 |
# for file_name in file_list:
|
113 |
+
# tasks.append(file_executer(file_name))
|
114 |
+
|
115 |
+
# await asyncio.gather(*tasks)#使用asyncio.gather(*tasks)来等待所有file_executer任务完成后再执行upload_video任务。
|
116 |
+
|
117 |
# if allow_submit:
|
|
|
118 |
# cover_img = cover_image.file.read()
|
119 |
# cover_img_data = Image.open(io.BytesIO(cover_img)).convert("L").convert("RGB")
|
120 |
# cover_path_to_image = os.path.join(cover_path, f"cover.jpg")
|
121 |
# cover_img_data.save(cover_path_to_image)
|
122 |
+
# background_tasks.add_task(upload_video, bili_meta_data, cover_path_to_image)
|
|
|
123 |
# return {"message": "提交video任务已加入队列"}
|
|
|
|
|
124 |
|
125 |
+
# return {"message": "Tasks added to the queue"}
|
126 |
|
|
|
127 |
@app.get("/execute_all_task")
|
128 |
+
async def execute_all_task(background_tasks: BackgroundTasks, file_list: List[str] = Query(["1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
|
129 |
bili_meta_data: dict = None, cover_image: UploadFile = File(...), mp4_out_file: str = 'mp4_out/output.mp4',
|
130 |
allow_submit: bool = False, cover_path: str = '/cover'
|
131 |
):
|
132 |
+
print("获取到file_list是:", file_list)
|
133 |
tasks = []
|
134 |
for file_name in file_list:
|
135 |
tasks.append(file_executer(file_name))
|
136 |
|
137 |
+
await asyncio.gather(*tasks)
|
138 |
|
139 |
if allow_submit:
|
140 |
cover_img = cover_image.file.read()
|
|
|
152 |
|
153 |
|
154 |
|
155 |
+
|
156 |
##########异步样例
|
157 |
def someTask():
|
158 |
time.sleep(20)
|