ONNX
Jacobmadwed commited on
Commit
b05935c
·
verified ·
1 Parent(s): 0cc113e

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +12 -9
handler.py CHANGED
@@ -146,13 +146,18 @@ class EndpointHandler:
146
  p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
147
  return p.replace("{prompt}", positive), n + " " + negative
148
 
149
- def load_image_from_path_or_url(path_or_url):
150
- if path_or_url.startswith("http://") or path_or_url.startswith("https://"):
151
- return load_image(path_or_url)
152
- else:
153
- return Image.open(path_or_url)
154
-
155
- face_image_path = data.pop("face_image_path", "raw/input.jpg")
 
 
 
 
 
156
  pose_image_path = data.pop("pose_image_path", None)
157
  style_name = data.pop("style_name", DEFAULT_STYLE_NAME)
158
  prompt = data.pop("inputs", "a man flying in the sky in Mars")
@@ -183,7 +188,6 @@ class EndpointHandler:
183
  # apply the style template
184
  prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
185
 
186
- face_image = load_image_from_path_or_url(face_image_path)
187
  face_image = resize_img(face_image, max_side=1024)
188
  face_image_cv2 = convert_from_image_to_cv2(face_image)
189
  height, width, _ = face_image_cv2.shape
@@ -261,4 +265,3 @@ class EndpointHandler:
261
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
262
 
263
  return {"generated_image_base64": img_str}
264
-
 
146
  p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
147
  return p.replace("{prompt}", positive), n + " " + negative
148
 
149
+ def load_image_from_base64(base64_str):
150
+ image_data = base64.b64decode(base64_str)
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 = load_image_from_path_or_url(face_image_path)
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")
 
188
  # apply the style template
189
  prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
190
 
 
191
  face_image = resize_img(face_image, max_side=1024)
192
  face_image_cv2 = convert_from_image_to_cv2(face_image)
193
  height, width, _ = face_image_cv2.shape
 
265
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
266
 
267
  return {"generated_image_base64": img_str}