Update handler.py
Browse files- handler.py +9 -4
handler.py
CHANGED
|
@@ -102,7 +102,6 @@ class EndpointHandler:
|
|
| 102 |
self.pipe.unet.to("cuda")
|
| 103 |
|
| 104 |
def __call__(self, data):
|
| 105 |
-
|
| 106 |
def convert_from_cv2_to_image(img: np.ndarray) -> Image:
|
| 107 |
return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
| 108 |
|
|
@@ -151,13 +150,18 @@ class EndpointHandler:
|
|
| 151 |
image = Image.open(io.BytesIO(image_data))
|
| 152 |
return image
|
| 153 |
|
|
|
|
|
|
|
|
|
|
| 154 |
face_image_base64 = data.pop("face_image_base64", None)
|
| 155 |
if face_image_base64 is not None:
|
|
|
|
| 156 |
face_image = load_image_from_base64(face_image_base64)
|
| 157 |
else:
|
|
|
|
| 158 |
face_image_path = data.pop("face_image_path", "raw/input.jpg")
|
| 159 |
-
face_image =
|
| 160 |
-
|
| 161 |
pose_image_path = data.pop("pose_image_path", None)
|
| 162 |
style_name = data.pop("style_name", DEFAULT_STYLE_NAME)
|
| 163 |
prompt = data.pop("inputs", "a man flying in the sky in Mars")
|
|
@@ -205,7 +209,7 @@ class EndpointHandler:
|
|
| 205 |
face_kps = draw_kps(convert_from_cv2_to_image(face_image_cv2), face_info["kps"])
|
| 206 |
img_controlnet = face_image
|
| 207 |
if pose_image_path is not None:
|
| 208 |
-
pose_image =
|
| 209 |
pose_image = resize_img(pose_image, max_side=1024)
|
| 210 |
img_controlnet = pose_image
|
| 211 |
pose_image_cv2 = convert_from_image_to_cv2(pose_image)
|
|
@@ -265,3 +269,4 @@ class EndpointHandler:
|
|
| 265 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 266 |
|
| 267 |
return {"generated_image_base64": img_str}
|
|
|
|
|
|
| 102 |
self.pipe.unet.to("cuda")
|
| 103 |
|
| 104 |
def __call__(self, data):
|
|
|
|
| 105 |
def convert_from_cv2_to_image(img: np.ndarray) -> Image:
|
| 106 |
return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
| 107 |
|
|
|
|
| 150 |
image = Image.open(io.BytesIO(image_data))
|
| 151 |
return image
|
| 152 |
|
| 153 |
+
# Debug: Print incoming data
|
| 154 |
+
print("Incoming data:", data)
|
| 155 |
+
|
| 156 |
face_image_base64 = data.pop("face_image_base64", None)
|
| 157 |
if face_image_base64 is not None:
|
| 158 |
+
print("Using provided base64 image")
|
| 159 |
face_image = load_image_from_base64(face_image_base64)
|
| 160 |
else:
|
| 161 |
+
print("No base64 image provided, using default path or URL")
|
| 162 |
face_image_path = data.pop("face_image_path", "raw/input.jpg")
|
| 163 |
+
face_image = load_image(face_image_path)
|
| 164 |
+
|
| 165 |
pose_image_path = data.pop("pose_image_path", None)
|
| 166 |
style_name = data.pop("style_name", DEFAULT_STYLE_NAME)
|
| 167 |
prompt = data.pop("inputs", "a man flying in the sky in Mars")
|
|
|
|
| 209 |
face_kps = draw_kps(convert_from_cv2_to_image(face_image_cv2), face_info["kps"])
|
| 210 |
img_controlnet = face_image
|
| 211 |
if pose_image_path is not None:
|
| 212 |
+
pose_image = load_image(pose_image_path)
|
| 213 |
pose_image = resize_img(pose_image, max_side=1024)
|
| 214 |
img_controlnet = pose_image
|
| 215 |
pose_image_cv2 = convert_from_image_to_cv2(pose_image)
|
|
|
|
| 269 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 270 |
|
| 271 |
return {"generated_image_base64": img_str}
|
| 272 |
+
|