Serkan Ozturk commited on
Commit
b9a007e
·
1 Parent(s): 3c52688
Files changed (1) hide show
  1. handler.py +14 -0
handler.py CHANGED
@@ -40,5 +40,19 @@ class EndpointHandler():
40
  img = torch.from_numpy(img).permute(2, 0, 1).unsqueeze(0).float()
41
  # Load the image
42
  upscaled = self.model(img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # postprocess the prediction
44
  return "OKAY"
 
40
  img = torch.from_numpy(img).permute(2, 0, 1).unsqueeze(0).float()
41
  # Load the image
42
  upscaled = self.model(img)
43
+ upscaled = upscaled.squeeze(0).permute(1,2,0)
44
+ upscaled = upscaled.numpy()
45
+
46
+ pil = Image.fromarray(upscaled)
47
+ # Save the image to a buffer
48
+ buffered = io.BytesIO()
49
+ pil.save(buffered, format="PNG")
50
+ img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
51
+
52
+ # Return a dictionary with the base64 image and additional data
53
+ return {
54
+ "image": img_str
55
+ }
56
+
57
  # postprocess the prediction
58
  return "OKAY"