asoderznik commited on
Commit
01e3be6
1 Parent(s): 22d7300

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +15 -9
handler.py CHANGED
@@ -24,8 +24,8 @@ class EndpointHandler():
24
  self.path = path
25
  # load the optimized model
26
  model_id = "stabilityai/stable-diffusion-x4-upscaler"
27
- self.pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
28
- self.pipe = self.pipe.to(device)
29
 
30
 
31
  def __call__(self, data) -> List[Dict[str, Any]]:
@@ -39,13 +39,19 @@ class EndpointHandler():
39
  inputs = data.get("inputs")
40
  logger.info('inputs received %s', inputs)
41
 
42
- decoded_image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
43
- with autocast(device.type):
44
- upscaled_image = self.pipe(prompt="", image = decoded_image).images[0]
 
 
 
 
 
45
 
46
- buffered = BytesIO()
47
- upscaled_image.save(buffered, format="JPEG")
48
- img_str = base64.b64encode(buffered.getvalue())
49
 
50
  # postprocess the prediction
51
- return {"image": img_str}
 
 
24
  self.path = path
25
  # load the optimized model
26
  model_id = "stabilityai/stable-diffusion-x4-upscaler"
27
+ #self.pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
28
+ #self.pipe = self.pipe.to(device)
29
 
30
 
31
  def __call__(self, data) -> List[Dict[str, Any]]:
 
39
  inputs = data.get("inputs")
40
  logger.info('inputs received %s', inputs)
41
 
42
+ image_base64 = base64.b64decode(inputs['image'])
43
+ logger.info('image_base64')
44
+ image_bytes = BytesIO(image_base64)
45
+ logger.info('image_bytes')
46
+ image = Image.open(image_bytes)
47
+ logger.info('image')
48
+ #with autocast(device.type):
49
+ # upscaled_image = self.pipe(prompt="", image = decoded_image).images[0]
50
 
51
+ #buffered = BytesIO()
52
+ #upscaled_image.save(buffered, format="JPEG")
53
+ #img_str = base64.b64encode(buffered.getvalue())
54
 
55
  # postprocess the prediction
56
+ #return {"image": img_str}
57
+ return {"image": "test"}