Skip to content

Commit 2f9641c

Browse files
committed
reformat for notebook
1 parent ee2a050 commit 2f9641c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

inference/generativeai/llm-workshop/lab12-hosting-controlnet-models-on-sagemaker/stable-diffusion-webui-async-inference-sagemaker-studio.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,23 +1580,25 @@
15801580
"import base64\n",
15811581
"import io\n",
15821582
"\n",
1583+
"\n",
15831584
"def encode_image_to_base64(image):\n",
15841585
" with io.BytesIO() as output_bytes:\n",
15851586
" if isinstance(image, dict):\n",
1586-
" image = image['image']\n",
1587-
" format = \"PNG\" if image.mode == 'RGBA' else \"JPEG\"\n",
1587+
" image = image[\"image\"]\n",
1588+
" format = \"PNG\" if image.mode == \"RGBA\" else \"JPEG\"\n",
15881589
" image.save(output_bytes, format=format)\n",
15891590
" bytes_data = output_bytes.getvalue()\n",
15901591
"\n",
15911592
" encoded_string = base64.b64encode(bytes_data)\n",
15921593
"\n",
15931594
" base64_str = str(encoded_string, \"utf-8\")\n",
1594-
" mimetype = \"image/jpeg\" if format == 'JPEG' else 'image/png'\n",
1595+
" mimetype = \"image/jpeg\" if format == \"JPEG\" else \"image/png\"\n",
15951596
" image_encoded_in_base64 = (\n",
15961597
" \"data:\" + (mimetype if mimetype is not None else \"\") + \";base64,\" + base64_str\n",
15971598
" )\n",
15981599
" return image_encoded_in_base64\n",
15991600
"\n",
1601+
"\n",
16001602
"def decode_base64_to_image(encoding):\n",
16011603
" if encoding.startswith(\"data:image/\"):\n",
16021604
" encoding = encoding.split(\";\")[1].split(\",\")[1]\n",

0 commit comments

Comments
 (0)