Spaces:
Running
Running
Update main.py
Browse files
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(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
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 |
|