Spaces:
Sleeping
Sleeping
Commit
·
2c23f30
1
Parent(s):
45ac234
add: swap image endpoint
Browse files- mannequin_to_model.py +19 -0
mannequin_to_model.py
CHANGED
|
@@ -76,6 +76,25 @@ async def mannequinToModel(
|
|
| 76 |
return response
|
| 77 |
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
@secure_router.get("/mannequin_catalogue")
|
| 80 |
async def returnJsonData(gender: str):
|
| 81 |
folderImageURL = supabase.storage.get_bucket("JSON").create_signed_url(
|
|
|
|
| 76 |
return response
|
| 77 |
|
| 78 |
|
| 79 |
+
@secure_router.get("/swap_image")
|
| 80 |
+
async def swapImage(image_one: UploadFile = File(...), ref_face: UploadFile = File(...)):
|
| 81 |
+
image_one, ref_face = await image_one.read(), await ref_face.read()
|
| 82 |
+
image_one_, ref_face_ = Image.open(BytesIO(image_one)), Image.open(BytesIO(ref_face))
|
| 83 |
+
|
| 84 |
+
mannequin_image = cv2.cvtColor(np.array(image_one_), cv2.COLOR_RGB2BGR)
|
| 85 |
+
person_image = cv2.cvtColor(np.array(ref_face_), cv2.COLOR_RGB2BGR)
|
| 86 |
+
result = pipeline.face_swap(mannequin_image, person_image)
|
| 87 |
+
result = Image.fromarray(cv2.cvtColor(result, cv2.COLOR_BGR2RGB))
|
| 88 |
+
inMemFile = BytesIO()
|
| 89 |
+
result.save(inMemFile, format="WEBP", quality=85)
|
| 90 |
+
outputBytes = inMemFile.getvalue()
|
| 91 |
+
response = {
|
| 92 |
+
"code": 200,
|
| 93 |
+
"output": f"data:image/WEBP;base64,{base64.b64encode(outputBytes).decode('utf-8')}",
|
| 94 |
+
}
|
| 95 |
+
return response
|
| 96 |
+
|
| 97 |
+
|
| 98 |
@secure_router.get("/mannequin_catalogue")
|
| 99 |
async def returnJsonData(gender: str):
|
| 100 |
folderImageURL = supabase.storage.get_bucket("JSON").create_signed_url(
|