|
47 | 47 | },
|
48 | 48 | {
|
49 | 49 | "cell_type": "code",
|
50 |
| - "execution_count": 1, |
| 50 | + "execution_count": 6, |
51 | 51 | "metadata": {},
|
52 | 52 | "outputs": [],
|
53 | 53 | "source": [
|
|
60 | 60 | },
|
61 | 61 | {
|
62 | 62 | "cell_type": "code",
|
63 |
| - "execution_count": 2, |
64 |
| - "metadata": {}, |
65 |
| - "outputs": [ |
66 |
| - { |
67 |
| - "name": "stdout", |
68 |
| - "output_type": "stream", |
69 |
| - "text": [ |
70 |
| - "sagemaker.config INFO - Not applying SDK defaults from location: /opt/homebrew/share/sagemaker/config.yaml\n", |
71 |
| - "sagemaker.config INFO - Not applying SDK defaults from location: /Users/itay/Library/Application Support/sagemaker/config.yaml\n" |
72 |
| - ] |
73 |
| - } |
74 |
| - ], |
| 63 | + "execution_count": 7, |
| 64 | + "metadata": {}, |
| 65 | + "outputs": [], |
75 | 66 | "source": [
|
76 | 67 | "import json\n",
|
77 | 68 | "from sagemaker import ModelPackage\n",
|
|
83 | 74 | },
|
84 | 75 | {
|
85 | 76 | "cell_type": "code",
|
86 |
| - "execution_count": 77, |
| 77 | + "execution_count": 37, |
87 | 78 | "metadata": {},
|
88 | 79 | "outputs": [],
|
89 | 80 | "source": [
|
90 | 81 | "# TODO delete\n",
|
91 | 82 | "import os\n",
|
92 |
| - "os.environ['AWS_PROFILE'] = 'marketplace-eng'\n", |
93 |
| - "# os.environ['AWS_PROFILE'] = 'octoml-sandbox-admin'\n", |
94 |
| - "#role = \"arn:aws:iam::006055839469:role/MarketplaceSageMakerValidationRole\" \n", |
95 |
| - "#role = \"arn:aws:iam::186900524924:role/SagemakerAdmin\"\n", |
| 83 | + "os.environ['AWS_PROFILE'] = 'octoml-sandbox-admin'\n", |
| 84 | + "role = \"arn:aws:iam::186900524924:role/SagemakerAdmin\"\n", |
96 | 85 | "\n",
|
97 | 86 | "boto_session = boto3.Session()\n",
|
98 | 87 | "region = boto_session.region_name\n",
|
|
104 | 93 | },
|
105 | 94 | {
|
106 | 95 | "cell_type": "code",
|
107 |
| - "execution_count": 87, |
| 96 | + "execution_count": 38, |
108 | 97 | "metadata": {},
|
109 | 98 | "outputs": [],
|
110 | 99 | "source": [
|
|
131 | 120 | },
|
132 | 121 | {
|
133 | 122 | "cell_type": "code",
|
134 |
| - "execution_count": 88, |
| 123 | + "execution_count": 39, |
135 | 124 | "metadata": {},
|
136 | 125 | "outputs": [],
|
137 | 126 | "source": [
|
|
198 | 187 | },
|
199 | 188 | {
|
200 | 189 | "cell_type": "code",
|
201 |
| - "execution_count": 73, |
| 190 | + "execution_count": 45, |
202 | 191 | "metadata": {},
|
203 | 192 | "outputs": [],
|
204 | 193 | "source": [
|
|
231 | 220 | },
|
232 | 221 | {
|
233 | 222 | "cell_type": "code",
|
234 |
| - "execution_count": 84, |
| 223 | + "execution_count": 46, |
235 | 224 | "metadata": {},
|
236 | 225 | "outputs": [],
|
237 | 226 | "source": [
|
|
280 | 269 | },
|
281 | 270 | {
|
282 | 271 | "cell_type": "code",
|
283 |
| - "execution_count": null, |
| 272 | + "execution_count": 43, |
284 | 273 | "metadata": {},
|
285 | 274 | "outputs": [],
|
286 | 275 | "source": [
|
|
321 | 310 | },
|
322 | 311 | {
|
323 | 312 | "cell_type": "code",
|
324 |
| - "execution_count": 5, |
| 313 | + "execution_count": null, |
325 | 314 | "metadata": {},
|
326 | 315 | "outputs": [],
|
327 | 316 | "source": [
|
|
346 | 335 | "response = runtime_sm_client.invoke_endpoint(\n",
|
347 | 336 | " EndpointName=model_name,\n",
|
348 | 337 | " ContentType=content_type,\n",
|
349 |
| - " Body=json.dumps(payload),\n", |
| 338 | + " Body=json.dumps(lightning_payload),\n", |
350 | 339 | ")\n",
|
351 | 340 | "\n",
|
352 | 341 | "output = json.loads(response[\"Body\"].read().decode(\"utf8\"))\n",
|
353 | 342 | "display_output(output)"
|
354 | 343 | ]
|
355 | 344 | },
|
| 345 | + { |
| 346 | + "cell_type": "markdown", |
| 347 | + "metadata": {}, |
| 348 | + "source": [ |
| 349 | + "Similar to generating images from text, we can also generate images from other images, utilizing the same performance and functionality (this also works with SDXL Lightning)" |
| 350 | + ] |
| 351 | + }, |
| 352 | + { |
| 353 | + "cell_type": "code", |
| 354 | + "execution_count": null, |
| 355 | + "metadata": {}, |
| 356 | + "outputs": [], |
| 357 | + "source": [ |
| 358 | + "import os\n", |
| 359 | + "from base64 import b64encode, b64decode\n", |
| 360 | + "\n", |
| 361 | + "# Read the image and encode it as base64\n", |
| 362 | + "init_image = b64encode(open('./astronaut.png', 'rb').read()).decode(\"utf-8\")\n", |
| 363 | + "\n", |
| 364 | + "img2img_payload = {\n", |
| 365 | + " \"prompt\": \"breathtaking, american woman, award winning photography, best quality, 8K HDR\",\n", |
| 366 | + " \"negative_prompt\": \"worst quality, low quality, bad quality, lazy eye\",\n", |
| 367 | + " \"width\": 1344,\n", |
| 368 | + " \"height\": 768,\n", |
| 369 | + " \"num_images\": 1,\n", |
| 370 | + " \"sampler\": \"DDIM\",\n", |
| 371 | + " \"steps\": 30,\n", |
| 372 | + " \"cfg_scale\": 12,\n", |
| 373 | + " \"use_refiner\": False,\n", |
| 374 | + " \"style_preset\": \"neon-punk\",\n", |
| 375 | + " \"strength\": 0.8,\n", |
| 376 | + " \"init_image\": init_image,\n", |
| 377 | + "\n", |
| 378 | + " # We use a specific seed to get a specific image out, but you can\n", |
| 379 | + " # change this or omit it\n", |
| 380 | + " \"seed\": 2701628909,\n", |
| 381 | + "}\n", |
| 382 | + "\n", |
| 383 | + "response = runtime_sm_client.invoke_endpoint(\n", |
| 384 | + " EndpointName=model_name,\n", |
| 385 | + " ContentType=content_type,\n", |
| 386 | + " Body=json.dumps(img2img_payload),\n", |
| 387 | + ")\n", |
| 388 | + "\n", |
| 389 | + "output = json.loads(response[\"Body\"].read().decode(\"utf8\"))\n", |
| 390 | + "display_output(output)\n", |
| 391 | + "\n", |
| 392 | + "# display original image too for comparison\n", |
| 393 | + "display.Image(b64decode(init_image))" |
| 394 | + ] |
| 395 | + }, |
356 | 396 | {
|
357 | 397 | "cell_type": "markdown",
|
358 | 398 | "metadata": {},
|
|
369 | 409 | },
|
370 | 410 | {
|
371 | 411 | "cell_type": "code",
|
372 |
| - "execution_count": 90, |
| 412 | + "execution_count": 35, |
373 | 413 | "metadata": {},
|
374 | 414 | "outputs": [],
|
375 | 415 | "source": [
|
|
393 | 433 | },
|
394 | 434 | {
|
395 | 435 | "cell_type": "code",
|
396 |
| - "execution_count": null, |
| 436 | + "execution_count": 36, |
397 | 437 | "metadata": {},
|
398 | 438 | "outputs": [],
|
399 | 439 | "source": [
|
400 | 440 | "model.delete_model()"
|
401 | 441 | ]
|
| 442 | + }, |
| 443 | + { |
| 444 | + "cell_type": "code", |
| 445 | + "execution_count": null, |
| 446 | + "metadata": {}, |
| 447 | + "outputs": [], |
| 448 | + "source": [] |
402 | 449 | }
|
403 | 450 | ],
|
404 | 451 | "metadata": {
|
|
0 commit comments