From 0d0e829cb9d9d53c6b7fa485be576be4a1372a2f Mon Sep 17 00:00:00 2001 From: ruchira-net Date: Fri, 22 Nov 2024 16:09:38 +1300 Subject: [PATCH 01/14] #1621 fix: correct escaping of backslashes in URL wrapping --- src/runtime/getUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js index 6c70a337..a28491fe 100644 --- a/src/runtime/getUrl.js +++ b/src/runtime/getUrl.js @@ -21,7 +21,7 @@ module.exports = (url, options) => { // Should url be wrapped? // See https://drafts.csswg.org/css-values-3/#urls if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) { - return `"${url.replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`; + return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n')}"`; } return url; From 65245c93c25973feb11e55b0119213620af95c28 Mon Sep 17 00:00:00 2001 From: ruchira-net Date: Wed, 27 Nov 2024 09:35:57 +1300 Subject: [PATCH 02/14] #1621 fix: complication error --- src/runtime/getUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js index a28491fe..a7c0bdc8 100644 --- a/src/runtime/getUrl.js +++ b/src/runtime/getUrl.js @@ -21,7 +21,7 @@ module.exports = (url, options) => { // Should url be wrapped? // See https://drafts.csswg.org/css-values-3/#urls if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) { - return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n')}"`; + return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`; } return url; From e027815f01d479ee376b408282cbaaf96c22bd49 Mon Sep 17 00:00:00 2001 From: ruchira-net Date: Wed, 27 Nov 2024 11:30:38 +1300 Subject: [PATCH 03/14] test: add snapshot and test case for URL escaping with backslashes (#1621) --- test/runtime/__snapshots__/getUrl.test.js.snap | 2 ++ test/runtime/getUrl.test.js | 1 + 2 files changed, 3 insertions(+) diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap index a4eda700..68a3c6dd 100644 --- a/test/runtime/__snapshots__/getUrl.test.js.snap +++ b/test/runtime/__snapshots__/getUrl.test.js.snap @@ -85,3 +85,5 @@ exports[`escape should escape url 41`] = `""image other.png#hash""`; exports[`escape should escape url 42`] = `""image other.png#hash""`; exports[`escape should escape url 43`] = `""image other.png#hash""`; + +exports[`escape should escape url 44`] = `"http://url/path\\/"`; diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js index 9dd2ae2b..ceb5b58e 100644 --- a/test/runtime/getUrl.test.js +++ b/test/runtime/getUrl.test.js @@ -127,5 +127,6 @@ describe("escape", () => { { hash: "#hash", needQuotes: true }, ), ).toMatchSnapshot(); + expect(getUrl("http://url/path\\/")).toMatchSnapshot(); }); }); From 28ca565fdc8680f706bf9fcd1ee1f3fff3407d7f Mon Sep 17 00:00:00 2001 From: ruchira-net Date: Tue, 3 Dec 2024 11:26:03 +1300 Subject: [PATCH 04/14] test: update URL snapshot and test case for escaping backslashes (#1621) --- test/runtime/__snapshots__/getUrl.test.js.snap | 2 +- test/runtime/getUrl.test.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap index 68a3c6dd..f25225d7 100644 --- a/test/runtime/__snapshots__/getUrl.test.js.snap +++ b/test/runtime/__snapshots__/getUrl.test.js.snap @@ -86,4 +86,4 @@ exports[`escape should escape url 42`] = `""image other.png#hash""`; exports[`escape should escape url 43`] = `""image other.png#hash""`; -exports[`escape should escape url 44`] = `"http://url/path\\/"`; +exports[`escape should escape url 44`] = `"https://www.example.com?path=path\\to\\resource"`; diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js index ceb5b58e..9d68e475 100644 --- a/test/runtime/getUrl.test.js +++ b/test/runtime/getUrl.test.js @@ -127,6 +127,8 @@ describe("escape", () => { { hash: "#hash", needQuotes: true }, ), ).toMatchSnapshot(); - expect(getUrl("http://url/path\\/")).toMatchSnapshot(); + expect( + getUrl("https://www.example.com?path=path\\to\\resource"), + ).toMatchSnapshot(); }); }); From a659d3e458c45a33dfa282b7a77629a89f7aa011 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Fri, 11 Apr 2025 22:26:28 +1200 Subject: [PATCH 05/14] Created using Colab --- stable_diffusion.ipynb | 107 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 stable_diffusion.ipynb diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb new file mode 100644 index 00000000..d6a23ad6 --- /dev/null +++ b/stable_diffusion.ipynb @@ -0,0 +1,107 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "stable-diffusion.ipynb", + "private_outputs": true, + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU", + "gpuClass": "standard" + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "source": [ + "%pip install --quiet --upgrade diffusers transformers accelerate mediapy peft" + ], + "metadata": { + "id": "ufD_d64nr08H" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "import mediapy as media\n", + "import random\n", + "import sys\n", + "import torch\n", + "\n", + "from diffusers import DiffusionPipeline, TCDScheduler\n", + "from huggingface_hub import hf_hub_download\n", + "\n", + "# Choose either 8 or 12 steps:\n", + "num_inference_steps = 35\n", + "\n", + "base_model_id = \"stabilityai/stable-diffusion-xl-base-1.0\"\n", + "repo_name = \"ByteDance/Hyper-SD\"\n", + "plural = \"s\" if num_inference_steps > 1 else \"\"\n", + "ckpt_name = f\"Hyper-SDXL-{num_inference_steps}step{plural}-CFG-lora.safetensors\"\n", + "device = \"cuda\"\n", + "\n", + "pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant=\"fp16\").to(device)\n", + "pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))\n", + "pipe.fuse_lora()\n", + "pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)" + ], + "metadata": { + "id": "bG2hkmSEvByV" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "prompt = \"a photo of Pikachu fine dining with a view to the Eiffel Tower\"\n", + "negative_prompt = \"text\"\n", + "seed = random.randint(0, sys.maxsize)\n", + "\n", + "# Pick a value between 5.0 and 8.0:\n", + "guidance_scale = 7\n", + "\n", + "# Decrease eta (min: 0, max: 1.0) to get more details with multi-step inference:\n", + "eta = 0.5\n", + "\n", + "images = pipe(\n", + " prompt = prompt,\n", + " negative_prompt = negative_prompt,\n", + " num_inference_steps = num_inference_steps,\n", + " guidance_scale = guidance_scale,\n", + " eta = eta,\n", + " generator = torch.Generator(device).manual_seed(seed),\n", + " ).images\n", + "\n", + "print(f\"Prompt:\\t{prompt}\\nSeed:\\t{seed}\")\n", + "media.show_images(images)\n", + "images[0].save(\"output.jpg\")" + ], + "metadata": { + "id": "AUc4QJfE-uR9" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From 796275111463ae1a63c8c5af4470dfe503c4273a Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Fri, 11 Apr 2025 22:27:59 +1200 Subject: [PATCH 06/14] Created using Colab --- stable_diffusion.ipynb | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index d6a23ad6..77558d5f 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -5,8 +5,7 @@ "colab": { "name": "stable-diffusion.ipynb", "private_outputs": true, - "provenance": [], - "include_colab_link": true + "provenance": [] }, "kernelspec": { "name": "python3", @@ -19,16 +18,6 @@ "gpuClass": "standard" }, "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, { "cell_type": "code", "source": [ @@ -74,9 +63,9 @@ { "cell_type": "code", "source": [ - "prompt = \"a photo of Pikachu fine dining with a view to the Eiffel Tower\"\n", + "prompt = \"Horror book cover in a gritty, gothic style, featuring a haunted mansion with eerie, glowing windows.\"\n", "negative_prompt = \"text\"\n", - "seed = random.randint(0, sys.maxsize)\n", + "seed = random.randint(0, 2147483647)\n", "\n", "# Pick a value between 5.0 and 8.0:\n", "guidance_scale = 7\n", From ed8e07375f549aee19ae222fca2631d5bea1a195 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Fri, 11 Apr 2025 22:32:52 +1200 Subject: [PATCH 07/14] Created using Colab --- stable_diffusion.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index 77558d5f..d5bc3704 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -41,7 +41,7 @@ "from huggingface_hub import hf_hub_download\n", "\n", "# Choose either 8 or 12 steps:\n", - "num_inference_steps = 35\n", + "num_inference_steps = 12\n", "\n", "base_model_id = \"stabilityai/stable-diffusion-xl-base-1.0\"\n", "repo_name = \"ByteDance/Hyper-SD\"\n", From 707ccac8e189d9533d5857ccec5786893b47da17 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 15:45:10 +1200 Subject: [PATCH 08/14] Created using Colab --- stable_diffusion.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index d5bc3704..e295fb31 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -76,6 +76,8 @@ "images = pipe(\n", " prompt = prompt,\n", " negative_prompt = negative_prompt,\n", + " height = 2560,\n", + " width = 1600,\n", " num_inference_steps = num_inference_steps,\n", " guidance_scale = guidance_scale,\n", " eta = eta,\n", From 5e9c67a3739ffcda25a057f3c12a3deb3cf12dbe Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 15:53:10 +1200 Subject: [PATCH 09/14] Created using Colab --- stable_diffusion.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index e295fb31..bfa1b891 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -63,7 +63,7 @@ { "cell_type": "code", "source": [ - "prompt = \"Horror book cover in a gritty, gothic style, featuring a haunted mansion with eerie, glowing windows.\"\n", + "prompt = \"Romance Horror book cover in a gritty, gothic style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopard coming from three directions, bat on sky\"\n", "negative_prompt = \"text\"\n", "seed = random.randint(0, 2147483647)\n", "\n", From 0a6694a2ae1465ada60df56a020beeb710c883bc Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 15:55:41 +1200 Subject: [PATCH 10/14] Created using Colab --- stable_diffusion.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index bfa1b891..e23c7bce 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -63,6 +63,8 @@ { "cell_type": "code", "source": [ + "torch.cuda.empty_cache()\n", + "\n", "prompt = \"Romance Horror book cover in a gritty, gothic style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopard coming from three directions, bat on sky\"\n", "negative_prompt = \"text\"\n", "seed = random.randint(0, 2147483647)\n", From e753506ed3c5f519a8f824cf3fa596b9506558b1 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 16:01:23 +1200 Subject: [PATCH 11/14] Created using Colab --- stable_diffusion.ipynb | 2 -- 1 file changed, 2 deletions(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index e23c7bce..d424fd6b 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -78,8 +78,6 @@ "images = pipe(\n", " prompt = prompt,\n", " negative_prompt = negative_prompt,\n", - " height = 2560,\n", - " width = 1600,\n", " num_inference_steps = num_inference_steps,\n", " guidance_scale = guidance_scale,\n", " eta = eta,\n", From ce08403b04eb69dcb7db571973671774ce35e7a8 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 17:09:33 +1200 Subject: [PATCH 12/14] Created using Colab --- stable_diffusion.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index d424fd6b..996bf7d2 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -63,9 +63,7 @@ { "cell_type": "code", "source": [ - "torch.cuda.empty_cache()\n", - "\n", - "prompt = \"Romance Horror book cover in a gritty, gothic style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopard coming from three directions, bat on sky\"\n", + "prompt = \"Romance Mystery book cover in a dark, noir style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopards, bat on sky\"\n", "negative_prompt = \"text\"\n", "seed = random.randint(0, 2147483647)\n", "\n", From 8c7841be239d7f211a63f7240018372a2c1bbeee Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sat, 12 Apr 2025 17:20:17 +1200 Subject: [PATCH 13/14] Created using Colab --- stable_diffusion.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable_diffusion.ipynb b/stable_diffusion.ipynb index 996bf7d2..da09c917 100644 --- a/stable_diffusion.ipynb +++ b/stable_diffusion.ipynb @@ -63,7 +63,7 @@ { "cell_type": "code", "source": [ - "prompt = \"Romance Mystery book cover in a dark, noir style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopards, bat on sky\"\n", + "prompt = \"Romance Horror book cover in a dark, noir style, featuring a haunted mansion with eerie, glowing windows in a dark forest. three leopards, bat on sky\"\n", "negative_prompt = \"text\"\n", "seed = random.randint(0, 2147483647)\n", "\n", From 32f34452748f38dd907bc625550670d9b433fe77 Mon Sep 17 00:00:00 2001 From: ruchira-net <91104117+ruchira-net@users.noreply.github.com> Date: Sun, 18 May 2025 16:38:51 +1200 Subject: [PATCH 14/14] Created using Colab --- Stable_Diffusion.ipynb | 343 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+) create mode 100644 Stable_Diffusion.ipynb diff --git a/Stable_Diffusion.ipynb b/Stable_Diffusion.ipynb new file mode 100644 index 00000000..ca086bd1 --- /dev/null +++ b/Stable_Diffusion.ipynb @@ -0,0 +1,343 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "gpuType": "T4", + "private_outputs": true, + "authorship_tag": "ABX9TyOiUWRZBuOHzRrD41UDa1vL", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "3he-zWjkTirt" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "aSGhPjR3Er-N" + }, + "outputs": [], + "source": [ + "#@title 👇 Installing dependencies { display-mode: \"form\" }\n", + "#@markdown ---\n", + "#@markdown Make sure to select **GPU** as the runtime type:
\n", + "#@markdown *Runtime->Change Runtime Type->Under Hardware accelerator, select GPU*\n", + "#@markdown\n", + "#@markdown ---\n", + "\n", + "!pip -q install torch torchvision tor diffusers transformers accelerate scipy safetensors xformers mediapy ipywidgets==7.7.1\n" + ] + }, + { + "cell_type": "code", + "source": [ + "#@title 👇 Selecting Model { form-width: \"20%\", display-mode: \"form\" }\n", + "#@markdown ---\n", + "#@markdown - **Select Model** - A list of Stable Diffusion models to choose from.\n", + "#@markdown - **Select Sampler** - A list of schedulers to choose from. Default is EulerAncestralScheduler.\n", + "#@markdown - **Safety Checker** - Enable/Disable uncensored content\n", + "#@markdown\n", + "#@markdown ---\n", + "\n", + "from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler\n", + "from diffusers.models import AutoencoderKL\n", + "import torch\n", + "import ipywidgets as widgets\n", + "import importlib\n", + "from PIL import Image\n", + "\n", + "#Enable third party widget support\n", + "from google.colab import output\n", + "output.enable_custom_widget_manager()\n", + "\n", + "#Pipe\n", + "pipe = None\n", + "\n", + "#Models\n", + "select_model = widgets.Dropdown(\n", + " options=[\n", + " (\"Dreamlike Photoreal 2.0\" , \"stabilityai/stable-diffusion-xl-base-1.0\")\n", + " ],\n", + " description=\"Select Model:\"\n", + ")\n", + "\n", + "#Schedulers\n", + "select_sampler = widgets.Dropdown(\n", + " options=[\n", + " \"EulerAncestralDiscreteScheduler\",\n", + " \"EulerDiscreteScheduler\",\n", + " \"UniPCMultistepScheduler\",\n", + " \"DDIMScheduler\"\n", + " ],\n", + " description=\"Select Schedular:\"\n", + ")\n", + "select_sampler.style.description_width = \"auto\"\n", + "\n", + "#Safety Checker\n", + "safety_check = widgets.Checkbox(\n", + " value=False,\n", + " description=\"Enable Safety Check\",\n", + " layout=widgets.Layout(margin=\"0px 0px 0px -85px\")\n", + ")\n", + "\n", + "#Output\n", + "out = widgets.Output()\n", + "\n", + "#Apply Settings\n", + "apply_btn = widgets.Button(\n", + " description=\"Apply\",\n", + " button_style=\"info\"\n", + ")\n", + "\n", + "\n", + "#Get scheduler\n", + "def get_scheduler(name):\n", + "\n", + " match name:\n", + "\n", + " case \"EulerAncestralDiscreteScheduler\":\n", + " return EulerAncestralDiscreteScheduler.from_pretrained(select_model.value, subfolder=\"scheduler\")\n", + "\n", + "#Run pipeline\n", + "def pipeline(p):\n", + "\n", + " global pipe\n", + "\n", + " out.clear_output()\n", + " apply_btn.disabled = True\n", + "\n", + " with out:\n", + "\n", + " print(\"Running, please wait...\")\n", + "\n", + " pipe = StableDiffusionPipeline.from_pretrained(\n", + " select_model.value,\n", + " scheduler=get_scheduler(select_sampler.value),\n", + " torch_dtype=torch.float16,\n", + " vae=AutoencoderKL.from_pretrained(\"stabilityai/sd-vae-ft-mse\", torch_dtype=torch.float16).to(\"cuda\")\n", + " ).to(\"cuda\")\n", + "\n", + " pipe.safety_checker = None\n", + "\n", + " pipe.enable_xformers_memory_efficient_attention()\n", + "\n", + " print(\"Finished!\")\n", + "\n", + " apply_btn.disabled = False\n", + "\n", + "\n", + "#Display\n", + "apply_btn.on_click(pipeline)\n", + "\n", + "widgets.VBox(\n", + " [\n", + " widgets.HTML(value=\"

Configure Pipeline

\"),\n", + " select_model, select_sampler, safety_check, apply_btn, out\n", + " ]\n", + ")\n", + "\n", + "#call pipeline method from here\n", + "pipeline(None)" + ], + "metadata": { + "id": "b_0UKcp3E9no" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "%env PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True" + ], + "metadata": { + "id": "ef0CwmfkmKOg" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#@title 👇 Generating Images { form-width: \"20%\", display-mode: \"form\" }\n", + "#@markdown ---\n", + "#@markdown - **Prompt** - Description of the image\n", + "#@markdown - **Negative Prompt** - Things you don't want to see or ignore in the image\n", + "#@markdown - **Steps** - Number of denoising steps. Higher steps may lead to better results but takes longer time to generate the image. Default is `30`.\n", + "#@markdown - **CFG** - Guidance scale ranging from `0` to `20`. Lower values allow the AI to be more creative and less strict at following the prompt. Default is `7.5`.\n", + "#@markdown - **Seed** - A random value that controls image generation. The same seed and prompt produce the same images. Set `-1` for using random seed values.\n", + "#@markdown ---\n", + "import ipywidgets as widgets, mediapy, random\n", + "import IPython.display\n", + "\n", + "\n", + "#PARAMETER WIDGETS\n", + "width = \"300px\"\n", + "\n", + "prompt = widgets.Textarea(\n", + " value=\"(photorealistic (HDR):2), (gorgeous:1.1), (only one:1.4) \",\n", + " placeholder=\"Enter prompt\",\n", + " #description=\"Prompt:\",\n", + " rows=5,\n", + " layout=widgets.Layout(width=\"600px\")\n", + ")\n", + "\n", + "camera = widgets.Dropdown(\n", + " options=[('leica summicron 35mm f2.0', ' leica summicron 35mm f2.0'), ('sony a7ii', ' sony a7ii'), ('kodak potra', ' kodak potra')],\n", + " value=' leica summicron 35mm f2.0',\n", + " description=\"Camera:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "lighting = widgets.Dropdown(\n", + " options=[('romantic lighting', ' romantic lighting,'), ('dramatic lighting', ' dramatic lighting,')],\n", + " value=' dramatic lighting,',\n", + " description=\"Lighting:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "neg_prompt = widgets.Textarea(\n", + " value=\"disfigured, bad lips, ugly lips, bad nose, ugly nose, bad face, ugly face, bad mouth, ugly mouth, beard, bad teeth, ugly teeth, ((grayscale)), cross-eyed, uneven eyes, bad ears, ugly ears, deformed, malformed limbs, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, fused thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, anime, unreal, animate, masculine, fat, chubby, (tamil:1.7), (red dot:2), (red mark:1.9), (pottu:1.8), (bindi:1.6), paintings, sketches, lowres, ((monochrome)), heavy make-up, (worst quality:1.6), (low quality:1.5), body hair, jewellary, topless, multiple people, blurry, duplicate bodies\",\n", + " placeholder=\"Enter negative prompt\",\n", + " #description=\"Negative Prompt:\",\n", + " rows=5,\n", + " layout=widgets.Layout(width=\"600px\")\n", + ")\n", + "\n", + "num_images = widgets.IntText(\n", + " value=4,\n", + " description=\"Images:\",\n", + " layout=widgets.Layout(width=width),\n", + ")\n", + "\n", + "steps = widgets.IntText(\n", + " value=35,\n", + " description=\"Steps:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "CFG = widgets.FloatText(\n", + " value=7,\n", + " description=\"CFG:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "img_height = widgets.Dropdown(\n", + " options=[('512px', 512), ('768px', 768), ('720px', 720)],\n", + " value=720,\n", + " description=\"Height:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "img_width = widgets.Dropdown(\n", + " options=[('512px', 512), ('768px', 768), ('1280px', 1280)],\n", + " value=1280,\n", + " description=\"Width:\",\n", + " layout=widgets.Layout(width=width)\n", + ")\n", + "\n", + "random_seed = widgets.IntText(\n", + " value=-1,\n", + " description=\"Seed:\",\n", + " layout=widgets.Layout(width=width),\n", + " disabled=False\n", + ")\n", + "\n", + "generate = widgets.Button(\n", + " description=\"Generate\",\n", + " disabled=False,\n", + " button_style=\"primary\"\n", + ")\n", + "\n", + "display_imgs = widgets.Output()\n", + "\n", + "\n", + "#RUN\n", + "def generate_img(i):\n", + "\n", + " #Clear output\n", + " display_imgs.clear_output()\n", + " generate.disabled = True\n", + "\n", + " #Calculate seed\n", + " seed = random.randint(0, 2147483647) if random_seed.value == -1 else random_seed.value\n", + "\n", + " with display_imgs:\n", + "\n", + " print(f\"Prompt:\\n{prompt.value + lighting.value + camera.value}\")\n", + "\n", + " images = pipe(\n", + " prompt.value + lighting.value + camera.value,\n", + " height = img_height.value,\n", + " width = img_width.value,\n", + " num_inference_steps = steps.value,\n", + " guidance_scale = CFG.value,\n", + " num_images_per_prompt = num_images.value,\n", + " negative_prompt = neg_prompt.value,\n", + " generator = torch.Generator(\"cuda\").manual_seed(seed),\n", + " ).images\n", + "\n", + " mediapy.show_images(images)\n", + "\n", + " print(f\"Seed:\\n{seed}\")\n", + "\n", + " generate.disabled = False\n", + "\n", + "#Display\n", + "generate.on_click(generate_img)\n", + "\n", + "widgets.VBox(\n", + " [\n", + " widgets.AppLayout(\n", + " header=widgets.VBox(\n", + " [camera, lighting]\n", + " ),\n", + " left_sidebar=widgets.VBox(\n", + " [num_images, steps, CFG, img_height, img_width, random_seed]\n", + " ),\n", + " center=widgets.VBox(\n", + " [prompt, neg_prompt, generate]\n", + " ),\n", + " right_sidebar=None,\n", + " footer=None\n", + " ),\n", + " display_imgs\n", + " ]\n", + ")" + ], + "metadata": { + "id": "-g-Q5UGcGATS" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file