Ashrafb commited on
Commit
47da34c
·
verified ·
1 Parent(s): 2c8cd2a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -7
main.py CHANGED
@@ -18,13 +18,16 @@ class ImageRequest(BaseModel):
18
  image_file: UploadFile = File(...)
19
 
20
  @app.post("/upload/")
21
- async def toonify_image(image_request: ImageRequest):
22
- image = await image_request.image_file.read()
23
- nparr = np.frombuffer(image, np.uint8)
24
- img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
25
- aligned_face, instyle, message = model.detect_and_align_image(img, 200, 200, 200, 200) # Hardcoded values
26
- toonified_img, message = model.image_toonify(aligned_face, instyle, exstyle, style_degree=0.5, style_type="cartoon1")
27
- return {"toonified_image": toonified_img, "message": message}
 
 
 
28
 
29
  app.mount("/", StaticFiles(directory="AB", html=True), name="static")
30
 
 
18
  image_file: UploadFile = File(...)
19
 
20
  @app.post("/upload/")
21
+ async def toonify_image(image_file: UploadFile = File(...)):
22
+ try:
23
+ contents = await image_file.read()
24
+ nparr = np.frombuffer(contents, np.uint8)
25
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
26
+ aligned_face, instyle, message = model.detect_and_align_image(img, 200, 200, 200, 200) # Hardcoded values
27
+ toonified_img, message = model.image_toonify(aligned_face, instyle, exstyle, style_degree=0.5, style_type="cartoon1")
28
+ return {"toonified_image": toonified_img, "message": message}
29
+ except Exception as e:
30
+ return {"error": str(e)}
31
 
32
  app.mount("/", StaticFiles(directory="AB", html=True), name="static")
33