Update main.py
Browse files
main.py
CHANGED
|
@@ -32,20 +32,22 @@ def get_face(faces, face_id):
|
|
| 32 |
|
| 33 |
app, swapper = prepare_app()
|
| 34 |
|
| 35 |
-
@app.
|
| 36 |
async def swap_faces(
|
| 37 |
-
sourceImage:
|
| 38 |
sourceFaceIndex: int = Form(...),
|
| 39 |
-
destinationImage:
|
| 40 |
destinationFaceIndex: int = Form(...)
|
| 41 |
):
|
| 42 |
"""Swaps faces between the source and destination images based on the specified face indices."""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
|
|
|
|
| 49 |
source_image = cv2.imdecode(source_np_array, cv2.IMREAD_COLOR)
|
| 50 |
destination_image = cv2.imdecode(destination_np_array, cv2.IMREAD_COLOR)
|
| 51 |
|
|
|
|
| 32 |
|
| 33 |
app, swapper = prepare_app()
|
| 34 |
|
| 35 |
+
@app.post("/swap_faces/")
|
| 36 |
async def swap_faces(
|
| 37 |
+
sourceImage: UploadFile = File(...),
|
| 38 |
sourceFaceIndex: int = Form(...),
|
| 39 |
+
destinationImage: UploadFile = File(...),
|
| 40 |
destinationFaceIndex: int = Form(...)
|
| 41 |
):
|
| 42 |
"""Swaps faces between the source and destination images based on the specified face indices."""
|
| 43 |
+
source_content = await sourceImage.read()
|
| 44 |
+
destination_content = await destinationImage.read()
|
| 45 |
+
|
| 46 |
+
# Convert image content to NumPy arrays
|
| 47 |
+
source_np_array = np.frombuffer(source_content, np.uint8)
|
| 48 |
+
destination_np_array = np.frombuffer(destination_content, np.uint8)
|
| 49 |
|
| 50 |
+
# Decode NumPy arrays into images
|
| 51 |
source_image = cv2.imdecode(source_np_array, cv2.IMREAD_COLOR)
|
| 52 |
destination_image = cv2.imdecode(destination_np_array, cv2.IMREAD_COLOR)
|
| 53 |
|