数据叨叨叨
如果是使用秋叶大佬的整合包,请勾选
text2img
import requests
from PIL import Image
import io
import base64
url = "http://127.0.0.1:7860"
payload = {
"prompt": "puppy dog",
"sampler" : "",
"batch_size": 1,
"width": 512,
"height": 512,
"steps": 20,
"negative_prompt": "wrong hands"
}
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()
r1 = response.json()['images'][0]
# image - Image.open(io.BytesIO(base64.b64decode(response.json()['images'][0])))
# image
print(r1)
image = base64.b64decode(response.json()['images'][0])
with open('1.jpg','wb') as f:
f.write(image)
img2img
import requests
from PIL import Image
import io
import base64
url = "http://127.0.0.1:7860"
img_code = base64.b64encode(open('2.jpg', 'rb').read())
print(img_code.decode())
img2img_data = {
"init_images":[
img_code.decode()
],
"prompt": "puppy boy",
"sampler" : "",
"batch_size": 1,
"width": 512,
"height": 512,
"steps": 20,
"negative_prompt": "wrong hands"
}
response = requests.post(url=f'{url}/sdapi/v1/img2img', json=img2img_data)
r = response.json()
r1 = response.json()['images'][0]
# image - Image.open(io.BytesIO(base64.b64decode(response.json()['images'][0])))
# image
print(r1)
image = base64.b64decode(response.json()['images'][0])
with open('3.jpg','wb') as f:
f.write(image)