michaelj commited on
Commit
45144b6
1 Parent(s): 04d0e09

fix base64

Browse files
Files changed (1) hide show
  1. main.py +8 -1
main.py CHANGED
@@ -55,7 +55,14 @@ async def predict(prompt=Body(...),imgbase64data=Body(...),userId=Body(None)):
55
  print("测试",output_image)
56
  print("s生成完成:", end2 - end1)
57
  # 将图片对象转换为bytes
58
- output_image_base64 = base64.b64encode(output_image.tobytes()).decode()
 
 
 
 
 
 
 
59
  print("完成的图片:", output_image_base64)
60
  logger = logging.getLogger('')
61
  logger.info(output_image_base64)
 
55
  print("测试",output_image)
56
  print("s生成完成:", end2 - end1)
57
  # 将图片对象转换为bytes
58
+ image_data = io.BytesIO()
59
+
60
+ # 将图像保存到BytesIO对象中,格式为JPEG
61
+ output_image.save(image_data, format='JPEG')
62
+
63
+ # 将BytesIO对象的内容转换为字节串
64
+ image_data_bytes = image_data.getvalue()
65
+ output_image_base64 = base64.b64encode(image_data_bytes).decode('utf-8')
66
  print("完成的图片:", output_image_base64)
67
  logger = logging.getLogger('')
68
  logger.info(output_image_base64)