michaelj commited on
Commit
aa021ca
1 Parent(s): 423e05a

changefile

Browse files
Files changed (1) hide show
  1. main.py +8 -6
main.py CHANGED
@@ -14,7 +14,7 @@ from diffusers.utils import load_image
14
  import base64
15
 
16
  app = FastAPI()
17
-
18
 
19
  #Endpoints
20
  #Root endpoints
@@ -26,7 +26,7 @@ def root():
26
  async def predict(url:str,prompt:str):
27
  MAX_QUEUE_SIZE = 4
28
  start = time.time()
29
- pipeline = get_pipeline()
30
 
31
  url = "https://img2.baidu.com/it/u=1845675188,2679793929&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500"
32
  prompt = "a nice Comfortable and clean. According to Baidu Education Information, the adjectives for a room include: comfortable, clean, beautiful, spacious, warm, quiet, luxurious, pleasant, exquisite, and warm ,colorful, light room width sofa,8k"
@@ -55,10 +55,12 @@ async def predict(url:str,prompt:str):
55
  print("s生成完成:", end2 - end1)
56
 
57
  output_image.save("./imageclm5.png")
58
- with open(output_image, 'rb') as image_file:
59
- encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
60
- print(encoded_string)
61
- return encoded_string
 
 
62
 
63
 
64
  @app.post("/predict")
 
14
  import base64
15
 
16
  app = FastAPI()
17
+ pipeline = get_pipeline()
18
 
19
  #Endpoints
20
  #Root endpoints
 
26
  async def predict(url:str,prompt:str):
27
  MAX_QUEUE_SIZE = 4
28
  start = time.time()
29
+
30
 
31
  url = "https://img2.baidu.com/it/u=1845675188,2679793929&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500"
32
  prompt = "a nice Comfortable and clean. According to Baidu Education Information, the adjectives for a room include: comfortable, clean, beautiful, spacious, warm, quiet, luxurious, pleasant, exquisite, and warm ,colorful, light room width sofa,8k"
 
55
  print("s生成完成:", end2 - end1)
56
 
57
  output_image.save("./imageclm5.png")
58
+ # 将图片对象转换为bytes
59
+ image_bytes = output_image.to_bytes()
60
+
61
+ # 对bytes进行base64编码
62
+ encoded_string = base64.b64encode(image_bytes).decode('utf-8')
63
+ return encoded_string
64
 
65
 
66
  @app.post("/predict")