Spaces:
Running
Running
update
Browse files
main.py
CHANGED
@@ -25,44 +25,38 @@ def root():
|
|
25 |
|
26 |
@app.post("/img2img")
|
27 |
async def predict(prompt=Body(...),imgbase64data=Body(...)):
|
|
|
28 |
MAX_QUEUE_SIZE = 4
|
29 |
start = time.time()
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
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=
|
47 |
strength=0.6,
|
48 |
seed=10,
|
49 |
-
width=
|
50 |
-
height=
|
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 |
|
|
|
25 |
|
26 |
@app.post("/img2img")
|
27 |
async def predict(prompt=Body(...),imgbase64data=Body(...)):
|
28 |
+
pipeline = get_pipeline()
|
29 |
MAX_QUEUE_SIZE = 4
|
30 |
start = time.time()
|
31 |
+
print("参数",imgbase64data,prompt)
|
32 |
+
image_data = base64.b64decode(imgbase64data)
|
33 |
+
image1 = Image.open(io.BytesIO(image_data))
|
34 |
+
w, h = image1.size
|
35 |
+
newW = 256
|
|
|
|
|
|
|
|
|
36 |
newH = int(h * newW / w)
|
37 |
+
img = image1.resize((newW, newH))
|
|
|
38 |
end1 = time.time()
|
39 |
+
now = datetime.now()
|
40 |
+
print(now)
|
41 |
+
print("图像:", img.size)
|
42 |
print("加载管道:", end1 - start)
|
43 |
result = pipeline(
|
44 |
prompt=prompt,
|
45 |
+
image=image1,
|
46 |
strength=0.6,
|
47 |
seed=10,
|
48 |
+
width=256,
|
49 |
+
height=256,
|
50 |
guidance_scale=1,
|
51 |
num_inference_steps=4,
|
52 |
)
|
53 |
output_image = result.images[0]
|
54 |
end2 = time.time()
|
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 |
return output_image_base64
|
61 |
|
62 |
|