Update main.py
Browse files
main.py
CHANGED
@@ -20,14 +20,19 @@ async def process_image(file: UploadFile = File(...)):
|
|
20 |
exstyle, load_info = model.load_model('cartoon1')
|
21 |
|
22 |
# Process the uploaded image
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Return the processed image
|
27 |
-
return FileResponse("result_image.jpg")
|
28 |
|
29 |
app.mount("/", StaticFiles(directory="AB", html=True), name="static")
|
30 |
|
31 |
@app.get("/")
|
32 |
def index() -> FileResponse:
|
33 |
return FileResponse(path="/app/AB/index.html", media_type="text/html")
|
|
|
|
20 |
exstyle, load_info = model.load_model('cartoon1')
|
21 |
|
22 |
# Process the uploaded image
|
23 |
+
aligned_face, _, input_info = model.detect_and_align_image("uploaded_image.jpg")
|
24 |
+
processed_image, message = model.image_toonify(aligned_face, exstyle, 'cartoon1', style_degree=0.5)
|
25 |
+
|
26 |
+
# Save the processed image
|
27 |
+
with open("result_image.jpg", "wb") as result_buffer:
|
28 |
+
result_buffer.write(processed_image)
|
29 |
|
30 |
# Return the processed image
|
31 |
+
return FileResponse("result_image.jpg", media_type="image/jpeg", headers={"Content-Disposition": "attachment; filename=result_image.jpg"})
|
32 |
|
33 |
app.mount("/", StaticFiles(directory="AB", html=True), name="static")
|
34 |
|
35 |
@app.get("/")
|
36 |
def index() -> FileResponse:
|
37 |
return FileResponse(path="/app/AB/index.html", media_type="text/html")
|
38 |
+
|