rogerxavier commited on
Commit
bc7dec9
1 Parent(s): c3dbb64

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +16 -1
api.py CHANGED
@@ -58,10 +58,14 @@ async def delete_files(directory: str):
58
  ########异步处理py文件执行接口
59
  def file_executer(file_name:str)->"执行返回":
60
  try:
 
61
  result = subprocess.check_output(["python", f"{file_name}.py"]).decode("utf-8")
62
- print("执行完成py任务:",file_name)
 
63
  return PlainTextResponse(result)
64
  except subprocess.CalledProcessError as e:
 
 
65
  return PlainTextResponse(f"Error executing {file_name}.py: {e}")
66
 
67
  @app.get("/execute_py_file/{file_name}")
@@ -73,6 +77,17 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
73
 
74
 
75
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
 
78
  ##########异步样例
 
58
  ########异步处理py文件执行接口
59
  def file_executer(file_name:str)->"执行返回":
60
  try:
61
+ print("开始执行py任务",file_name)
62
  result = subprocess.check_output(["python", f"{file_name}.py"]).decode("utf-8")
63
+ print("执行完成py任务:",file_name,"结果如下")
64
+ print(PlainTextResponse(result))
65
  return PlainTextResponse(result)
66
  except subprocess.CalledProcessError as e:
67
+ print("执行py任务失败",file_name,"原因如下")
68
+ print(PlainTextResponse(f"Error executing {file_name}.py: {e}"))
69
  return PlainTextResponse(f"Error executing {file_name}.py: {e}")
70
 
71
  @app.get("/execute_py_file/{file_name}")
 
77
 
78
 
79
 
80
+ #收到图片后为了后台任务的顺序,单独设定一个函数依次将1去水印,2裁剪,3合并按照顺序加入后台任务队列
81
+ @app.get("/execute_all_task")
82
+ async def execute_all_task(background_tasks: BackgroundTasks):
83
+ background_tasks.add_task(file_executer,"1removeMask")
84
+ background_tasks.add_task(file_executer,"2magiDialogCut")
85
+ background_tasks.add_task(file_executer,"3mergeDialogToVideo")
86
+ return {"message": "Tasks added to the queue"}
87
+
88
+
89
+
90
+
91
 
92
 
93
  ##########异步样例