rogerxavier commited on
Commit
fdf65e3
1 Parent(s): 02f726e

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +17 -16
api.py CHANGED
@@ -101,40 +101,40 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
101
 
102
 
103
 
104
- #收到图片后为了后台任务的顺序,单独设定一个函数依次将自定义执行顺序加入队列 ,有默认参数的写后面-并且和bili合并,不然还要等output.mp4生成后才能发起提交请求
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
- # background_tasks.add_task(file_executer, file_name)
 
 
 
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
- # #video数据从meta用户请求获取,至于
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: list = ["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)#使用asyncio.gather(*tasks)来等待所有file_executer任务完成后再执行upload_video任务。
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)