Skip to content

Commit

Permalink
Merge branch 'main' into fp16_web
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-garvey authored Jun 22, 2023
2 parents 0f2f671 + 1a8e202 commit afda6c2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/stable_diffusion/src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def set_init_device_flags():
):
args.use_tuned = False

elif (
args.height != args.width and "rdna2" in args.iree_vulkan_target_triple
):
args.use_tuned = False

elif base_model_id not in [
"Linaqruf/anything-v3.0",
"dreamlike-art/dreamlike-diffusion-1.0",
Expand Down
4 changes: 4 additions & 0 deletions apps/stable_diffusion/web/ui/img2img_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ def img2img_api(
lora_hf_id="",
ondemand=False,
)

# Converts generator type to subscriptable
res = list(res)[0]

return {
"images": encode_pil_to_base64(res[0]),
"parameters": {},
Expand Down
3 changes: 3 additions & 0 deletions apps/stable_diffusion/web/ui/upscaler_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def upscaler_api(
lora_hf_id="",
ondemand=False,
)
# Converts generator type to subscriptable
res = list(res)[0]

return {
"images": encode_pil_to_base64(res[0]),
"parameters": {},
Expand Down
109 changes: 109 additions & 0 deletions rest_api_tests/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import requests
from PIL import Image
import base64
from io import BytesIO


def upscaler_test():
# Define values here
prompt = ""
negative_prompt = ""
seed = 2121991605
height = 512
width = 512
steps = 50
noise_level = 10
cfg_scale = 7
image_path = r"./rest_api_tests/dog.png"

# Converting Image to base64
img_file = open(image_path, "rb")
init_images = [
"data:image/png;base64," + base64.b64encode(img_file.read()).decode()
]

url = "http://127.0.0.1:8080/sdapi/v1/upscaler"

headers = {
"User-Agent": "PythonTest",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
}

data = {
"prompt": prompt,
"negative_prompt": negative_prompt,
"seed": seed,
"height": height,
"width": width,
"steps": steps,
"noise_level": noise_level,
"cfg_scale": cfg_scale,
"init_images": init_images,
}

res = requests.post(url=url, json=data, headers=headers, timeout=1000)

print(f"response from server was : {res.status_code}")


def img2img_test():
# Define values here
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
denoising_strength = 0.75
cfg_scale = 7
image_path = r"./rest_api_tests/dog.png"

# Converting Image to Base64
img_file = open(image_path, "rb")
init_images = [
"data:image/png;base64," + base64.b64encode(img_file.read()).decode()
]

url = "http://127.0.0.1:8080/sdapi/v1/img2img"

headers = {
"User-Agent": "PythonTest",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
}

data = {
"prompt": prompt,
"negative_prompt": negative_prompt,
"init_images": init_images,
"height": height,
"width": width,
"steps": steps,
"denoising_strength": denoising_strength,
"cfg_scale": cfg_scale,
"seed": seed,
}

res = requests.post(url=url, json=data, headers=headers, timeout=1000)

print(f"response from server was : {res.status_code}")

print("Extracting response object")

# 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")


if __name__ == "__main__":
img2img_test()
upscaler_test()
Binary file added rest_api_tests/dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit afda6c2

Please sign in to comment.