Ashrafb commited on
Commit
d4eab99
·
verified ·
1 Parent(s): 2d8cdb8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -8
main.py CHANGED
@@ -32,20 +32,22 @@ def get_face(faces, face_id):
32
 
33
  app, swapper = prepare_app()
34
 
35
- @app.get("/swap_faces/")
36
  async def swap_faces(
37
- sourceImage: str = Form(...),
38
  sourceFaceIndex: int = Form(...),
39
- destinationImage: str = Form(...),
40
  destinationFaceIndex: int = Form(...)
41
  ):
42
  """Swaps faces between the source and destination images based on the specified face indices."""
43
- source_image_data = base64.b64decode(sourceImage)
44
- destination_image_data = base64.b64decode(destinationImage)
45
-
46
- source_np_array = np.frombuffer(source_image_data, np.uint8)
47
- destination_np_array = np.frombuffer(destination_image_data, np.uint8)
 
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