dmingod commited on
Commit
d829b71
·
1 Parent(s): 32a2c12
Files changed (1) hide show
  1. handler.py +6 -6
handler.py CHANGED
@@ -6,7 +6,7 @@ from io import BytesIO
6
  from PIL import Image
7
  from diffusers import StableDiffusionXLImg2ImgPipeline
8
  from diffusers.utils import load_image
9
-
10
 
11
 
12
  class EndpointHandler():
@@ -41,17 +41,16 @@ class EndpointHandler():
41
 
42
  # process image
43
  if encoded_image is not None:
44
- image = self.decode_base64_image(encoded_image)
45
  print("Image is getting loaded")
46
  else:
47
  print("Image is None")
48
  image = None
49
 
50
- imgLen = len(image)
51
 
52
  print(f"Prompt: {inputs}, strength: {strength}, inf steps: {num_inference_steps}, denoise start: {denoising_start}, denoise_end: {denoising_end}")
53
  print(f"Imgs per prompt: {num_images_per_prompt}, aesthetic_score: {aesthetic_score}, guidance_scale: {guidance_scale}, negative_prompt: {negative_prompt}")
54
- print(f"Image size: {imgLen}")
55
  # run inference pipeline
56
  out = self.pipe(inputs,
57
  image=image,
@@ -71,6 +70,7 @@ class EndpointHandler():
71
  # helper to decode input image
72
  def decode_base64_image(self, image_string):
73
  base64_image = base64.b64decode(image_string)
74
- buffer = BytesIO(base64_image)
75
  image = Image.open(buffer)
76
- return image
 
 
6
  from PIL import Image
7
  from diffusers import StableDiffusionXLImg2ImgPipeline
8
  from diffusers.utils import load_image
9
+ import numpy as np
10
 
11
 
12
  class EndpointHandler():
 
41
 
42
  # process image
43
  if encoded_image is not None:
44
+ image = self.decode_base64_image(encoded_image)
45
  print("Image is getting loaded")
46
  else:
47
  print("Image is None")
48
  image = None
49
 
 
50
 
51
  print(f"Prompt: {inputs}, strength: {strength}, inf steps: {num_inference_steps}, denoise start: {denoising_start}, denoise_end: {denoising_end}")
52
  print(f"Imgs per prompt: {num_images_per_prompt}, aesthetic_score: {aesthetic_score}, guidance_scale: {guidance_scale}, negative_prompt: {negative_prompt}")
53
+
54
  # run inference pipeline
55
  out = self.pipe(inputs,
56
  image=image,
 
70
  # helper to decode input image
71
  def decode_base64_image(self, image_string):
72
  base64_image = base64.b64decode(image_string)
73
+ buffer = io.BytesIO(base64_image)
74
  image = Image.open(buffer)
75
+ pil_image = Image.fromarray(np.array(image))
76
+ return pil_image