Ashrafb commited on
Commit
237989a
·
verified ·
1 Parent(s): edc3c34

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -6
main.py CHANGED
@@ -59,13 +59,25 @@ def inference(img_path, Style, if_face=None):
59
  print('global exception', error)
60
  return None, None
61
 
 
 
 
 
 
 
62
  @app.post("/inference/")
63
- async def inference_api(request: InferenceRequest):
64
- img_path = request.img_path
65
- Style = request.Style
66
- if_face = request.if_face
67
- output, save_path = inference(img_path, Style, if_face)
68
- return {"output": output, "save_path": save_path}
 
 
 
 
 
 
69
 
70
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
71
 
 
59
  print('global exception', error)
60
  return None, None
61
 
62
+
63
+
64
+
65
+
66
+
67
+
68
  @app.post("/inference/")
69
+ async def inference_api(file: UploadFile = File(...), Style: str = Form(...), if_face: str = Form(...)):
70
+ try:
71
+ contents = await file.read()
72
+ img_path = f"input.{file.filename}"
73
+ with open(img_path, "wb") as f:
74
+ f.write(contents)
75
+
76
+ output, save_path = inference(img_path, Style, if_face)
77
+
78
+ return FileResponse(save_path)
79
+ except Exception as e:
80
+ return {"error": str(e)}
81
 
82
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
83