File size: 1,460 Bytes
194b4ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#!/bin/python3
from PIL import Image
import requests, base64, io, argparse
SD_WEBUI = 'http://127.0.0.1:7860'
parser = argparse.ArgumentParser()
parser.add_argument('filename')
args = parser.parse_args()
with open(args.filename, 'rb') as image_file:
base64_image = base64.b64encode(image_file.read()).decode('utf-8')
payload = {
"input_image": base64_image,
"detection_prompt": "background",
"positive_prompt": "waterfall",
"sam_model_name": "sam_hq_vit_h.pth",
"dino_model_name": "GroundingDINO_SwinB (938MB)",
"use_hires_fix": True,
"scripts": { # "scripts" has the same format with "alwayson_scripts" in /sdapi/v1/txt2img
"controlnet": {
"args": [
{ # See ControlNetUnit dataclass for all possible fields
"enabled": True,
"module": "openpose_full",
"model": "control_v11p_sd15_openpose [cab727d4]",
},
]
},
"soft inpainting": { # Default args from UI, recommended hight "mask_blur"
"args": [False, 1, 0.5, 4, 0, 1, 2]
},
},
}
response = requests.post(url=f'{SD_WEBUI}/replacer/replace', json=payload)
if response.status_code == 200:
response = response.json()
if response['info']:
print(response['info'])
if response['image']:
Image.open(io.BytesIO(base64.b64decode(response['image']))).show()
else:
print(response.json())
|