Spaces:
Running
Running
Update main.py
Browse files
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 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
newH = int(h * newW / w)
|
36 |
-
|
|
|
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=
|
45 |
strength=0.6,
|
46 |
seed=10,
|
47 |
-
width=
|
48 |
-
height=
|
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 |
|