michaelj commited on
Commit
99f940b
1 Parent(s): e4b8c77

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -12
main.py CHANGED
@@ -27,35 +27,42 @@ def root():
27
  async def predict(prompt=Body(...),imgbase64data=Body(...)):
28
  MAX_QUEUE_SIZE = 4
29
  start = time.time()
30
- print("参数",imgbase64data,prompt)
31
- image_data = base64.b64decode(imgbase64data)
32
- image1 = Image.open(io.BytesIO(image_data))
33
- w, h = image1.size
34
- newW = 256
 
 
 
 
35
  newH = int(h * newW / w)
36
- img = image1.resize((newW, newH))
 
37
  end1 = time.time()
38
- now = datetime.now()
39
- print(now)
40
- print("图像:", img.size)
41
  print("加载管道:", end1 - start)
42
  result = pipeline(
43
  prompt=prompt,
44
- image=image1,
45
  strength=0.6,
46
  seed=10,
47
- width=256,
48
- height=256,
49
  guidance_scale=1,
50
  num_inference_steps=4,
51
  )
52
  output_image = result.images[0]
53
  end2 = time.time()
54
  print("测试",output_image)
 
 
 
55
  print("s生成完成:", end2 - end1)
56
  # 将图片对象转换为bytes
 
57
  output_image_base64 = base64.b64encode(output_image.tobytes()).decode()
58
  print("完成的图片:", output_image_base64)
 
59
  return output_image_base64
60
 
61
 
 
27
  async def predict(prompt=Body(...),imgbase64data=Body(...)):
28
  MAX_QUEUE_SIZE = 4
29
  start = time.time()
30
+ pipeline = get_pipeline()
31
+
32
+ url = "https://img2.baidu.com/it/u=1845675188,2679793929&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500"
33
+ 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"
34
+
35
+ init_image = load_image(url).convert("RGB")
36
+ # image1 = replace_background(init_image.resize((256, 256)))
37
+ w, h = init_image.size
38
+ newW = 512
39
  newH = int(h * newW / w)
40
+
41
+ img = init_image.resize((newW, newH))
42
  end1 = time.time()
 
 
 
43
  print("加载管道:", end1 - start)
44
  result = pipeline(
45
  prompt=prompt,
46
+ image=img,
47
  strength=0.6,
48
  seed=10,
49
+ width=512,
50
+ height=512,
51
  guidance_scale=1,
52
  num_inference_steps=4,
53
  )
54
  output_image = result.images[0]
55
  end2 = time.time()
56
  print("测试",output_image)
57
+ print("s生成完成:", end2 - end1)
58
+ end2 = time.time()
59
+ print("测试",output_image)
60
  print("s生成完成:", end2 - end1)
61
  # 将图片对象转换为bytes
62
+ end3 = time.time()
63
  output_image_base64 = base64.b64encode(output_image.tobytes()).decode()
64
  print("完成的图片:", output_image_base64)
65
+ print("图像转换时间:", end3 - end2)
66
  return output_image_base64
67
 
68