├── README.md ├── sdxl_turbo_diffusers_colab.ipynb ├── sdxl_turbo_diffusers_gradio_colab.ipynb └── wip ├── sd_turbo_diffusers_colab.ipynb ├── sd_turbo_diffusers_gradio_colab.ipynb ├── sdxl_turbo_colab.ipynb ├── sdxl_turbo_controlnet_canny_draw_colab.ipynb └── sdxl_turbo_diffusers_draw_colab.ipynb /README.md: -------------------------------------------------------------------------------- 1 | 🐣 Please follow me for new updates https://twitter.com/camenduru
2 | 🔥 Please join our discord server https://discord.gg/k5BwmmvJJU
3 | 🥳 Please join my patreon community https://patreon.com/camenduru
4 | 5 | # 🚦 WIP 🚦 6 | 7 | ## 🦒 Colab 8 | 9 | | Colab | Info 10 | | --- | --- | 11 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_diffusers_colab.ipynb) | sdxl_turbo_diffusers_colab 12 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_diffusers_gradio_colab.ipynb) | sdxl_turbo_diffusers_gradio_colab 13 | 14 | ## Main Repo 15 | https://github.com/Stability-AI/generative-models 16 | 17 | ## Paper 18 | https://arxiv.org/abs/2311.17042
19 | https://static1.squarespace.com/static/6213c340453c3f502425776e/t/65663480a92fba51d0e1023f/1701197769659/adversarial_diffusion_distillation.pdf
20 | 21 | ## Page 22 | https://stability.ai/research/adversarial-diffusion-distillation 23 | 24 | ## Output 25 | 26 | ![Screenshot 2023-11-29 030726](https://github.com/camenduru/sdxl-turbo-colab/assets/54370274/3dba4903-3b0a-4ffd-9dca-bc5e8301271e) 27 | -------------------------------------------------------------------------------- /sdxl_turbo_diffusers_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_diffusers_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install diffusers transformers accelerate\n", 21 | "\n", 22 | "from diffusers import AutoPipelineForText2Image\n", 23 | "import torch\n", 24 | "pipe = AutoPipelineForText2Image.from_pretrained(\"stabilityai/sdxl-turbo\", torch_dtype=torch.float16, variant=\"fp16\").to(\"cuda\")" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "prompt = \"duck\"\n", 34 | "image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]" 35 | ] 36 | } 37 | ], 38 | "metadata": { 39 | "accelerator": "GPU", 40 | "colab": { 41 | "gpuType": "T4", 42 | "provenance": [] 43 | }, 44 | "kernelspec": { 45 | "display_name": "Python 3", 46 | "name": "python3" 47 | }, 48 | "language_info": { 49 | "name": "python" 50 | } 51 | }, 52 | "nbformat": 4, 53 | "nbformat_minor": 0 54 | } 55 | -------------------------------------------------------------------------------- /sdxl_turbo_diffusers_gradio_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_diffusers_gradio_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install -q diffusers transformers accelerate peft gradio==3.50.2\n", 21 | "\n", 22 | "from diffusers import AutoPipelineForText2Image\n", 23 | "import torch\n", 24 | "\n", 25 | "pipe = AutoPipelineForText2Image.from_pretrained(\"stabilityai/sdxl-turbo\", torch_dtype=torch.float16, variant=\"fp16\").to(\"cuda\")\n", 26 | "\n", 27 | "import os\n", 28 | "import shlex\n", 29 | "import subprocess\n", 30 | "from pathlib import Path\n", 31 | "from typing import Union\n", 32 | "\n", 33 | "id_rsa_file = \"/content/id_rsa\"\n", 34 | "id_rsa_pub_file = \"/content/id_rsa.pub\"\n", 35 | "if os.path.exists(id_rsa_file):\n", 36 | " os.remove(id_rsa_file)\n", 37 | "if os.path.exists(id_rsa_pub_file):\n", 38 | " os.remove(id_rsa_pub_file)\n", 39 | "\n", 40 | "def gen_key(path: Union[str, Path]) -> None:\n", 41 | " path = Path(path)\n", 42 | " arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n", 43 | " args = shlex.split(arg_string)\n", 44 | " subprocess.run(args, check=True)\n", 45 | " path.chmod(0o600)\n", 46 | "\n", 47 | "gen_key(id_rsa_file)\n", 48 | "\n", 49 | "import threading\n", 50 | "def tunnel():\n", 51 | " !ssh -R 80:127.0.0.1:7860 -o StrictHostKeyChecking=no -i /content/id_rsa remote.moe\n", 52 | "threading.Thread(target=tunnel, daemon=True).start()\n", 53 | "\n", 54 | "import gradio as gr\n", 55 | "\n", 56 | "def generate(prompt):\n", 57 | " image = pipe(prompt, num_inference_steps=1, guidance_scale=0.0, width=512, height=512).images[0]\n", 58 | " return image.resize((512, 512))\n", 59 | "\n", 60 | "with gr.Blocks(title=f\"Realtime SDXL Turbo\", css=\".gradio-container {max-width: 544px !important}\") as demo:\n", 61 | " with gr.Row():\n", 62 | " with gr.Column():\n", 63 | " textbox = gr.Textbox(show_label=False, value=\"a close-up picture of a fluffy cat\")\n", 64 | " button = gr.Button()\n", 65 | " with gr.Row(variant=\"default\"):\n", 66 | " output_image = gr.Image(\n", 67 | " show_label=False,\n", 68 | " type=\"pil\",\n", 69 | " interactive=False,\n", 70 | " height=512,\n", 71 | " width=512,\n", 72 | " elem_id=\"output_image\",\n", 73 | " )\n", 74 | "\n", 75 | " # textbox.change(fn=generate, inputs=[textbox], outputs=[output_image], show_progress=False)\n", 76 | " button.click(fn=generate, inputs=[textbox], outputs=[output_image], show_progress=False)\n", 77 | "\n", 78 | "demo.queue().launch(inline=False, share=True, debug=True)" 79 | ] 80 | } 81 | ], 82 | "metadata": { 83 | "accelerator": "GPU", 84 | "colab": { 85 | "gpuType": "T4", 86 | "provenance": [] 87 | }, 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "name": "python" 94 | } 95 | }, 96 | "nbformat": 4, 97 | "nbformat_minor": 0 98 | } 99 | -------------------------------------------------------------------------------- /wip/sd_turbo_diffusers_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sd_turbo_diffusers_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install diffusers transformers accelerate\n", 21 | "\n", 22 | "from diffusers import StableDiffusionPipeline\n", 23 | "import torch\n", 24 | "pipe = StableDiffusionPipeline.from_pretrained(\"stabilityai/sd-turbo\", torch_dtype=torch.float16).to(\"cuda\")" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "prompt = \"duck\"\n", 34 | "image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]" 35 | ] 36 | } 37 | ], 38 | "metadata": { 39 | "accelerator": "GPU", 40 | "colab": { 41 | "gpuType": "T4", 42 | "provenance": [] 43 | }, 44 | "kernelspec": { 45 | "display_name": "Python 3", 46 | "name": "python3" 47 | }, 48 | "language_info": { 49 | "name": "python" 50 | } 51 | }, 52 | "nbformat": 4, 53 | "nbformat_minor": 0 54 | } 55 | -------------------------------------------------------------------------------- /wip/sd_turbo_diffusers_gradio_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sd_turbo_diffusers_gradio_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install -q diffusers transformers accelerate peft gradio==3.50.2\n", 21 | "\n", 22 | "from diffusers import StableDiffusionPipeline\n", 23 | "import torch\n", 24 | "\n", 25 | "pipe = StableDiffusionPipeline.from_pretrained(\"stabilityai/sd-turbo\", torch_dtype=torch.float16).to(\"cuda\")\n", 26 | "\n", 27 | "import os\n", 28 | "import shlex\n", 29 | "import subprocess\n", 30 | "from pathlib import Path\n", 31 | "from typing import Union\n", 32 | "\n", 33 | "id_rsa_file = \"/content/id_rsa\"\n", 34 | "id_rsa_pub_file = \"/content/id_rsa.pub\"\n", 35 | "if os.path.exists(id_rsa_file):\n", 36 | " os.remove(id_rsa_file)\n", 37 | "if os.path.exists(id_rsa_pub_file):\n", 38 | " os.remove(id_rsa_pub_file)\n", 39 | "\n", 40 | "def gen_key(path: Union[str, Path]) -> None:\n", 41 | " path = Path(path)\n", 42 | " arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n", 43 | " args = shlex.split(arg_string)\n", 44 | " subprocess.run(args, check=True)\n", 45 | " path.chmod(0o600)\n", 46 | "\n", 47 | "gen_key(id_rsa_file)\n", 48 | "\n", 49 | "import threading\n", 50 | "def tunnel():\n", 51 | " !ssh -R 80:127.0.0.1:7860 -o StrictHostKeyChecking=no -i /content/id_rsa remote.moe\n", 52 | "threading.Thread(target=tunnel, daemon=True).start()\n", 53 | "\n", 54 | "import gradio as gr\n", 55 | "\n", 56 | "def generate(prompt):\n", 57 | " image = pipe(prompt, num_inference_steps=1, guidance_scale=0.0, width=512, height=512).images[0]\n", 58 | " return image.resize((512, 512))\n", 59 | "\n", 60 | "with gr.Blocks(title=f\"Realtime SDXL Turbo\", css=\".gradio-container {max-width: 544px !important}\") as demo:\n", 61 | " with gr.Row():\n", 62 | " with gr.Column():\n", 63 | " textbox = gr.Textbox(show_label=False, value=\"a close-up picture of a fluffy cat\")\n", 64 | " button = gr.Button()\n", 65 | " with gr.Row(variant=\"default\"):\n", 66 | " output_image = gr.Image(\n", 67 | " show_label=False,\n", 68 | " type=\"pil\",\n", 69 | " interactive=False,\n", 70 | " height=512,\n", 71 | " width=512,\n", 72 | " elem_id=\"output_image\",\n", 73 | " )\n", 74 | "\n", 75 | " # textbox.change(fn=generate, inputs=[textbox], outputs=[output_image], show_progress=False)\n", 76 | " button.click(fn=generate, inputs=[textbox], outputs=[output_image], show_progress=False)\n", 77 | "\n", 78 | "demo.queue().launch(inline=False, share=True, debug=True)" 79 | ] 80 | } 81 | ], 82 | "metadata": { 83 | "accelerator": "GPU", 84 | "colab": { 85 | "gpuType": "T4", 86 | "provenance": [] 87 | }, 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "name": "python" 94 | } 95 | }, 96 | "nbformat": 4, 97 | "nbformat_minor": 0 98 | } 99 | -------------------------------------------------------------------------------- /wip/sdxl_turbo_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "%cd /content\n", 21 | "!git clone -b turbo https://github.com/camenduru/generative-models\n", 22 | "%cd /content/generative-models\n", 23 | "\n", 24 | "!apt -y install -qq aria2\n", 25 | "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/sdxl-turbo/resolve/main/sd_xl_turbo_1.0_fp16.safetensors -d /content/generative-models/checkpoints -o sd_xl_turbo_1.0.safetensors\n", 26 | "\n", 27 | "!pip install -q streamlit einops invisible-watermark omegaconf pytorch_lightning kornia open-clip-torch streamlit-keyup\n", 28 | "!pip install -q https://download.pytorch.org/whl/cu121/xformers-0.0.22.post7-cp310-cp310-manylinux2014_x86_64.whl\n", 29 | "!pip install -q git+https://github.com/openai/CLIP.git\n", 30 | "!pip install -q -e .\n", 31 | "\n", 32 | "import os\n", 33 | "import shlex\n", 34 | "import subprocess\n", 35 | "from pathlib import Path\n", 36 | "from typing import Union\n", 37 | "\n", 38 | "id_rsa_file = \"/content/id_rsa\"\n", 39 | "id_rsa_pub_file = \"/content/id_rsa.pub\"\n", 40 | "if os.path.exists(id_rsa_file):\n", 41 | " os.remove(id_rsa_file)\n", 42 | "if os.path.exists(id_rsa_pub_file):\n", 43 | " os.remove(id_rsa_pub_file)\n", 44 | "\n", 45 | "def gen_key(path: Union[str, Path]) -> None:\n", 46 | " path = Path(path)\n", 47 | " arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n", 48 | " args = shlex.split(arg_string)\n", 49 | " subprocess.run(args, check=True)\n", 50 | " path.chmod(0o600)\n", 51 | "\n", 52 | "gen_key(id_rsa_file)\n", 53 | "\n", 54 | "import threading\n", 55 | "def tunnel():\n", 56 | " !ssh -R 80:127.0.0.1:8501 -o StrictHostKeyChecking=no -i /content/id_rsa remote.moe\n", 57 | "threading.Thread(target=tunnel, daemon=True).start()\n", 58 | "\n", 59 | "!streamlit run /content/generative-models/scripts/demo/turbo.py" 60 | ] 61 | } 62 | ], 63 | "metadata": { 64 | "accelerator": "GPU", 65 | "colab": { 66 | "gpuType": "T4", 67 | "provenance": [] 68 | }, 69 | "kernelspec": { 70 | "display_name": "Python 3", 71 | "name": "python3" 72 | }, 73 | "language_info": { 74 | "name": "python" 75 | } 76 | }, 77 | "nbformat": 4, 78 | "nbformat_minor": 0 79 | } 80 | -------------------------------------------------------------------------------- /wip/sdxl_turbo_controlnet_canny_draw_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_controlnet_canny_draw_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install git+https://github.com/huggingface/diffusers -U\n", 21 | "!pip install -q controlnet-aux transformers accelerate peft gradio==3.50.2\n", 22 | "!pip install -q https://download.pytorch.org/whl/cu121/xformers-0.0.22.post7-cp310-cp310-manylinux2014_x86_64.whl\n", 23 | "\n", 24 | "from diffusers import StableDiffusionControlNetPipeline, UNet2DConditionModel, ControlNetModel, LCMScheduler\n", 25 | "import torch\n", 26 | "\n", 27 | "controlnet = ControlNetModel.from_pretrained(\"lllyasviel/control_v11p_sd15_canny\", torch_dtype=torch.float16)\n", 28 | "pipe = StableDiffusionControlNetPipeline.from_pretrained(\"stabilityai/sdxl-turbo\", controlnet=controlnet, torch_dtype=torch.float16, variant=\"fp16\").to(\"cuda\")\n", 29 | "pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)\n", 30 | "pipe.load_lora_weights(\"latent-consistency/lcm-lora-sdv1-5\")\n", 31 | "\n", 32 | "import cv2\n", 33 | "import numpy as np\n", 34 | "from PIL import Image\n", 35 | "import gradio as gr\n", 36 | "\n", 37 | "def generate_canny(input_image, threshold1, threshold2):\n", 38 | " input_image = np.array(input_image)\n", 39 | " input_image = cv2.Canny(input_image, threshold1, threshold2)\n", 40 | " input_image = input_image[:, :, None]\n", 41 | " input_image = np.concatenate([input_image, input_image, input_image], axis=2)\n", 42 | " canny_image = Image.fromarray(input_image)\n", 43 | " return canny_image.resize((512, 768))\n", 44 | "\n", 45 | "def generate(prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image):\n", 46 | " image = pipe(prompt, negative_prompt=negative_prompt, image=canny_image, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, controlnet_conditioning_scale=float(controlnet_conditioning_scale), cross_attention_kwargs={\"scale\": float(scale)}).images[0]\n", 47 | " config = \" | \".join([f\"prompt: {prompt}\", f\"negative_prompt: {negative_prompt}\", f\"controlnet_conditioning_scale: {controlnet_conditioning_scale}\", f\"scale: {scale}\", f\"num_inference_steps: {num_inference_steps}\", f\"guidance_scale: {guidance_scale}\"])\n", 48 | " return image.resize((512, 768)), config\n", 49 | "\n", 50 | "with gr.Blocks(title=f\"Realtime Latent Consistency Model\") as demo:\n", 51 | " with gr.Box(scale=23):\n", 52 | " with gr.Row():\n", 53 | " with gr.Column():\n", 54 | " with gr.Row():\n", 55 | " prompt = gr.Textbox(show_label=False, value=\"1girl red dress\")\n", 56 | " with gr.Row():\n", 57 | " negative_prompt = gr.Textbox(show_label=False, value=\"blurry\")\n", 58 | " with gr.Column():\n", 59 | " with gr.Row():\n", 60 | " scale = gr.Slider(minimum=0, maximum=1, step=0.1, value=1, label=\"lora_scale\")\n", 61 | " threshold1 = gr.Slider(minimum=0, maximum=500, step=1, value=100, label=\"threshold1\")\n", 62 | " threshold2 = gr.Slider(minimum=0, maximum=500, step=1, value=200, label=\"threshold2\")\n", 63 | " with gr.Row():\n", 64 | " num_inference_steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, label=\"num_inference_steps\")\n", 65 | " guidance_scale = gr.Slider(minimum=0, maximum=10, step=0.5, value=1, label=\"guidance_scale\")\n", 66 | " controlnet_conditioning_scale = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label=\"controlnet_scale\")\n", 67 | " with gr.Row():\n", 68 | " input_image = gr.Image(\n", 69 | " show_label=False,\n", 70 | " type=\"pil\",\n", 71 | " tool=\"color-sketch\",\n", 72 | " source=\"canvas\",\n", 73 | " width=512,\n", 74 | " height=768,\n", 75 | " brush_radius=5.0,\n", 76 | " interactive=True,\n", 77 | " )\n", 78 | " canny_image = gr.Image(\n", 79 | " show_label=False,\n", 80 | " type=\"pil\",\n", 81 | " tool=\"color-sketch\",\n", 82 | " source=\"upload\",\n", 83 | " interactive=True,\n", 84 | " width=512,\n", 85 | " height=768,\n", 86 | " )\n", 87 | " output_image = gr.Image(\n", 88 | " show_label=False,\n", 89 | " type=\"pil\",\n", 90 | " tool=\"color-sketch\",\n", 91 | " source=\"upload\",\n", 92 | " interactive=False,\n", 93 | " width=512,\n", 94 | " height=768,\n", 95 | " )\n", 96 | " with gr.Row():\n", 97 | " config = gr.Label(show_label=False)\n", 98 | "\n", 99 | " input_image.change(fn=generate_canny, inputs=[input_image, threshold1, threshold2], outputs=[canny_image], show_progress=False)\n", 100 | " threshold1.change(fn=generate_canny, inputs=[input_image, threshold1, threshold2], outputs=[canny_image], show_progress=False)\n", 101 | " threshold2.change(fn=generate_canny, inputs=[input_image, threshold1, threshold2], outputs=[canny_image], show_progress=False)\n", 102 | " prompt.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 103 | " negative_prompt.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 104 | " controlnet_conditioning_scale.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 105 | " scale.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 106 | " num_inference_steps.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 107 | " guidance_scale.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 108 | " canny_image.change(fn=generate, inputs=[prompt, negative_prompt, controlnet_conditioning_scale, scale, num_inference_steps, guidance_scale, canny_image], outputs=[output_image, config], show_progress=False)\n", 109 | " \n", 110 | "demo.launch(inline=False, share=True, debug=True)" 111 | ] 112 | } 113 | ], 114 | "metadata": { 115 | "accelerator": "GPU", 116 | "colab": { 117 | "gpuType": "T4", 118 | "provenance": [] 119 | }, 120 | "kernelspec": { 121 | "display_name": "Python 3", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "name": "python" 126 | } 127 | }, 128 | "nbformat": 4, 129 | "nbformat_minor": 0 130 | } 131 | -------------------------------------------------------------------------------- /wip/sdxl_turbo_diffusers_draw_colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/sdxl-turbo-colab/blob/main/sdxl_turbo_diffusers_draw_colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "VjYy0F2gZIPR" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install -q diffusers transformers accelerate peft gradio==3.50.2\n", 21 | "\n", 22 | "from diffusers import AutoPipelineForText2Image\n", 23 | "import torch\n", 24 | "\n", 25 | "pipe = AutoPipelineForText2Image.from_pretrained(\"stabilityai/sdxl-turbo\", torch_dtype=torch.float16, variant=\"fp16\").to(\"cuda\")\n", 26 | "pipe.set_progress_bar_config(disable=True)\n", 27 | "\n", 28 | "import gradio as gr\n", 29 | "\n", 30 | "def generate(prompt, input_image):\n", 31 | " image = pipe(prompt, image=input_image, num_inference_steps=1, guidance_scale=0.0, strength=0.5).images[0]\n", 32 | " return image.resize((768, 768))\n", 33 | "\n", 34 | "with gr.Blocks(title=f\"Realtime Latent Consistency Model\") as demo:\n", 35 | " with gr.Row():\n", 36 | " with gr.Column(scale=23):\n", 37 | " textbox = gr.Textbox(show_label=False, value=\"a close-up picture of a fluffy cat\")\n", 38 | "\n", 39 | " with gr.Row(variant=\"default\"):\n", 40 | " input_image = gr.Image(\n", 41 | " show_label=False,\n", 42 | " type=\"pil\",\n", 43 | " tool=\"color-sketch\",\n", 44 | " source=\"canvas\",\n", 45 | " height=742,\n", 46 | " width=742,\n", 47 | " brush_radius=10.0,\n", 48 | " )\n", 49 | " output_image = gr.Image(\n", 50 | " show_label=False,\n", 51 | " type=\"pil\",\n", 52 | " interactive=False,\n", 53 | " height=742,\n", 54 | " width=742,\n", 55 | " elem_id=\"output_image\",\n", 56 | " )\n", 57 | "\n", 58 | " textbox.change(fn=generate, inputs=[textbox, input_image], outputs=[output_image], show_progress=False)\n", 59 | " input_image.change(fn=generate, inputs=[textbox, input_image], outputs=[output_image], show_progress=False)\n", 60 | "\n", 61 | "demo.launch(inline=False, share=True)" 62 | ] 63 | } 64 | ], 65 | "metadata": { 66 | "accelerator": "GPU", 67 | "colab": { 68 | "gpuType": "T4", 69 | "provenance": [] 70 | }, 71 | "kernelspec": { 72 | "display_name": "Python 3", 73 | "name": "python3" 74 | }, 75 | "language_info": { 76 | "name": "python" 77 | } 78 | }, 79 | "nbformat": 4, 80 | "nbformat_minor": 0 81 | } 82 | --------------------------------------------------------------------------------