From 59995387ccb9f373edfc75f799fdfd63a95a6e06 Mon Sep 17 00:00:00 2001 From: AyaanShah2204 Date: Thu, 22 Jun 2023 14:55:23 -0700 Subject: [PATCH 1/3] fixed inpaint api --- apps/stable_diffusion/web/ui/inpaint_ui.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/stable_diffusion/web/ui/inpaint_ui.py b/apps/stable_diffusion/web/ui/inpaint_ui.py index 082668e85b..be8a58def4 100644 --- a/apps/stable_diffusion/web/ui/inpaint_ui.py +++ b/apps/stable_diffusion/web/ui/inpaint_ui.py @@ -278,7 +278,7 @@ def inpaint_api( custom_model="None", hf_model_id=InputData["hf_model_id"] if "hf_model_id" in InputData.keys() - else "stabilityai/stable-diffusion-2-1-base", + else "stabilityai/stable-diffusion-2-inpainting", custom_vae="None", precision="fp16", device=available_devices[0], @@ -289,6 +289,10 @@ def inpaint_api( lora_hf_id="", ondemand=False, ) + + # Converts generator type to subscriptable + res = next(res) + return { "images": encode_pil_to_base64(res[0]), "parameters": {}, From e43a6322c19950a275d10d9da06db7696b2f11d5 Mon Sep 17 00:00:00 2001 From: AyaanShah2204 Date: Thu, 22 Jun 2023 14:58:31 -0700 Subject: [PATCH 2/3] added inpainting test --- rest_api_tests/api_test.py | 67 ++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/rest_api_tests/api_test.py b/rest_api_tests/api_test.py index 844dcfd58b..f0b9023deb 100644 --- a/rest_api_tests/api_test.py +++ b/rest_api_tests/api_test.py @@ -91,19 +91,66 @@ def img2img_test(): print("Extracting response object") - # Uncomment below to save the picture + # NOTE Uncomment below to save the picture + + # response_obj = res.json() + # img_b64 = response_obj.get("images", [False])[0] or response_obj.get( + # "image" + # ) + # img_b2 = base64.b64decode(img_b64.replace("data:image/png;base64,", "")) + # im_file = BytesIO(img_b2) + # response_img = Image.open(im_file) + # print("Saving Response Image to: response_img") + # response_img.save(r"rest_api_tests/response_img.png") + +def inpainting_test(): + prompt = "Paint a rabbit riding on the dog" + negative_prompt = "ugly, bad art, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, tiling, signature, cut off, draft" + seed = 2121991605 + height = 512 + width = 512 + steps = 50 + noise_level = 10 + cfg_scale = 7 + is_full_res = False + full_res_padding = 32 + image_path = r"./rest_api_tests/dog.png" + + img_file = open(image_path, "rb") + image = "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + img_file = open(image_path, "rb") + mask = "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + + url = "http://127.0.0.1:8080/sdapi/v1/inpaint" + + headers = { + "User-Agent": "PythonTest", + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + } + + data = { + "prompt": prompt, + "negative_prompt": negative_prompt, + "image": image, + "mask" : mask, + "height": height, + "width": width, + "steps": steps, + "noise_level": noise_level, + "cfg_scale": cfg_scale, + "seed": seed, + "is_full_res" : is_full_res, + "full_res_padding" : full_res_padding + } + + res = requests.post(url=url, json=data, headers=headers, timeout=1000) + + print(f"[Inpainting] response from server was : {res.status_code}") - response_obj = res.json() - img_b64 = response_obj.get("images", [False])[0] or response_obj.get( - "image" - ) - img_b2 = base64.b64decode(img_b64.replace("data:image/png;base64,", "")) - im_file = BytesIO(img_b2) - response_img = Image.open(im_file) - print("Saving Response Image to: response_img") - response_img.save(r"rest_api_tests/response_img.png") if __name__ == "__main__": img2img_test() upscaler_test() + inpainting_test() From f822fc14962ca8675f7372124a3e312632490ae2 Mon Sep 17 00:00:00 2001 From: AyaanShah2204 Date: Thu, 22 Jun 2023 15:04:05 -0700 Subject: [PATCH 3/3] fixed linter errors --- rest_api_tests/api_test.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rest_api_tests/api_test.py b/rest_api_tests/api_test.py index f0b9023deb..2265e06d26 100644 --- a/rest_api_tests/api_test.py +++ b/rest_api_tests/api_test.py @@ -103,6 +103,7 @@ def img2img_test(): # print("Saving Response Image to: response_img") # response_img.save(r"rest_api_tests/response_img.png") + def inpainting_test(): prompt = "Paint a rabbit riding on the dog" negative_prompt = "ugly, bad art, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, tiling, signature, cut off, draft" @@ -117,9 +118,13 @@ def inpainting_test(): image_path = r"./rest_api_tests/dog.png" img_file = open(image_path, "rb") - image = "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + image = ( + "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + ) img_file = open(image_path, "rb") - mask = "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + mask = ( + "data:image/png;base64," + base64.b64encode(img_file.read()).decode() + ) url = "http://127.0.0.1:8080/sdapi/v1/inpaint" @@ -133,15 +138,15 @@ def inpainting_test(): "prompt": prompt, "negative_prompt": negative_prompt, "image": image, - "mask" : mask, + "mask": mask, "height": height, "width": width, "steps": steps, "noise_level": noise_level, "cfg_scale": cfg_scale, "seed": seed, - "is_full_res" : is_full_res, - "full_res_padding" : full_res_padding + "is_full_res": is_full_res, + "full_res_padding": full_res_padding, } res = requests.post(url=url, json=data, headers=headers, timeout=1000) @@ -149,7 +154,6 @@ def inpainting_test(): print(f"[Inpainting] response from server was : {res.status_code}") - if __name__ == "__main__": img2img_test() upscaler_test()