Zhibinhong commited on
Commit
dd3b112
·
1 Parent(s): 13b296f

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +8 -5
handler.py CHANGED
@@ -16,8 +16,11 @@ class EndpointHandler():
16
 
17
  inputs=data['inputs']
18
  text=inputs.pop('text',data)
19
- image = self.pipe(text).images[0]
20
- print(type(image))
21
- img_data = image.tobytes()
22
- img_base64 = base64.b64encode(img_data).decode('utf-8')
23
- return {'image':img_base64}
 
 
 
 
16
 
17
  inputs=data['inputs']
18
  text=inputs.pop('text',data)
19
+ img = self.pipe(text).images[0]
20
+ # 将图像转换为字节流
21
+ img_byte_arr = io.BytesIO()
22
+ img.save(img_byte_arr, format='JPEG')
23
+
24
+ # 将字节流编码为base64格式
25
+ encoded_string = base64.b64encode(img_byte_arr.getvalue())
26
+ return {'image':encoded_string}