Skip to content

Instantly share code, notes, and snippets.

@CypherpunkSamurai
Created December 20, 2022 10:22
Show Gist options
  • Select an option

  • Save CypherpunkSamurai/e5aff8828cdf3cc7711730e411640712 to your computer and use it in GitHub Desktop.

Select an option

Save CypherpunkSamurai/e5aff8828cdf3cc7711730e411640712 to your computer and use it in GitHub Desktop.
Colab-Stable-diffusion

Colab Stable Diffusion

This contains all popular colab stable diffusion notebooks released.

Display the source blob
Display the rendered blob
Raw
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"stable-diffusion.ipynb","private_outputs":true,"provenance":[{"file_id":"https://github.com/woctezuma/stable-diffusion-colab/blob/main/stable_diffusion.ipynb","timestamp":1671530870869}]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU","gpuClass":"standard"},"cells":[{"cell_type":"markdown","source":["# **Colab Stable diffusion**\n","**This is a edit of colab stable diffusion.**\n","\n","---\n","\n","## Changelog:\n","- Added Euler Ancestral Scheduler\n","\n","## Credits:\n","- woctezuma/stable-diffusion-colab\n","\n","---"],"metadata":{"id":"54MqXhGQ4gpi"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"QuFz5uGi-h6G","cellView":"form"},"outputs":[],"source":["#@title Install Requirements\n","%pip install --quiet --upgrade diffusers transformers scipy mediapy accelerate ftfy spacy"]},{"cell_type":"code","source":["#@title Install xformers\n","import subprocess\n","\n","# The xformers package is mandatory to be able to create several 768x768 images.\n","github_url = \"https://github.com/brian6091/xformers-wheels\"\n","xformer_id = \"0.0.15.dev0+4c06c79\"\n","xformers_wheels = f\"xformers-{xformer_id}.d20221205-cp38-cp38-linux_x86_64.whl\"\n","\n","# Install xformers using pre-compiled Python wheels\n","%pip install -q {github_url}/releases/download/{xformer_id}/{xformers_wheels}"],"metadata":{"id":"oP_dBQpSCIkY","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Version\n","# model_id = \"stabilityai/stable-diffusion-2-1-base\"\n","model_id = \"stabilityai/stable-diffusion-2-1\" #@param {type: \"string\"} [\"stabilityai/stable-diffusion-2-1\", \"stabilityai/stable-diffusion-2\", \"runwayml/stable-diffusion-v1-5\", \"CompVis/stable-diffusion-v1-4\"]"],"metadata":{"id":"GR4vF2bw-sHR","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["from diffusers import PNDMScheduler, DDIMScheduler, LMSDiscreteScheduler, DPMSolverMultistepScheduler, EulerDiscreteScheduler, EulerAncestralDiscreteScheduler\n","\n","#@title Samplers\n","\n","sampler = \"EulerA\" #@param {type: \"string\"} [\"Euler\", \"EulerA\", \"PNDM\", \"DDIM\", \"DPMS\", \"LMSD\"]\n","\n","# scheduler = PNDMScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","# scheduler = DDIMScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","# scheduler = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","# scheduler = LMSDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","# scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","# scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\"\n","\n","scheduler = None\n","\n","# We assign the scheduler\n","if sampler == \"Euler\":\n"," scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","elif sampler == \"EulerA\":\n"," scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","elif sampler == \"PNDM\":\n"," scheduler = PNDMScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","elif sampler == \"DDIM\":\n"," scheduler = DDIMScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","elif sampler == \"DPM\":\n"," scheduler = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","elif sampler == \"LMSD\":\n"," scheduler = LMSDiscreteScheduler.from_pretrained(model_id, subfolder=\"scheduler\")\n","else:\n"," print(\"Invalid Sampler...\")"],"metadata":{"id":"vF9Q0xKX8gLR","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Init Pipeline\n","import mediapy as media\n","import torch\n","from diffusers import StableDiffusionPipeline\n","\n","device = \"cuda\"\n","\n","pipe = StableDiffusionPipeline.from_pretrained(\n"," model_id,\n"," scheduler=scheduler,\n"," torch_dtype=torch.float16,\n"," revision=\"fp16\",\n"," )\n","pipe = pipe.to(device)\n","pipe.enable_xformers_memory_efficient_attention()\n","\n","# Not required\n","#if model_id.endswith('-base'):\n","# image_length = 512\n","# else:\n"," # image_length = 768"],"metadata":{"id":"bG2hkmSEvByV","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Generate Images\n","prompt = \"A ((beautiful woman)), smiling, beautiful face, nude, (high res)\" #@param {type: \"string\"}\n","neg_prompt = \"((deformed)), deformed limbs, multiple limbs, multiple arms, ((ugly)), fat, black and white, watermark\" #@param {type: \"string\"}\n","num_images = 1 #@param {type: \"integer\"}\n","\n","# 512 (if model_id.endswith('-base')) or 768 \n","image_length = 8 #@param {type:\"slider\", min:8, max:1024, step:8}\n","#@markdown **Note:** Image Length needs to be a Multiple of 8\n","\n","steps = 55 #@param {type:\"slider\", min:0, max:150, step:1}\n","cfgscale = 8 #@param {type:\"slider\", min:0, max:30, step:1.5}\n","\n","images = pipe(\n"," prompt,\n"," negative_prompt=neg_prompt,\n"," num_images_per_prompt=num_images,\n"," guidance_scale=cfgscale,\n"," num_inference_steps=steps,\n"," height=image_length,\n"," width=image_length,\n"," ).images\n"," \n","media.show_images(images)\n","images[0].save(\"output.jpg\")"],"metadata":{"id":"AUc4QJfE-uR9","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["<center>\n","<img align=\"center\" src=\"https://i.imgur.com/8dx0ipm.png\">\n","</center>\n","\n","<br>"],"metadata":{"id":"Tdda6eGa9yyE"}},{"cell_type":"markdown","source":["## Prompt Engineering\n","Here's some resources:\n","\n","## Websites\n","- https://playgroundai.com/\n","- http://novelai.io/\n","- https://desuarchive.org/g/search/text/masterpiece%20high%20quality/ (4chan)\n","- https://www.ptsearch.info/home/\n","- https://aiguidebook.top/\n","\n","## Rentry\n","- https://rentry.org/voldy\n","- https://rentry.org/sdupdates\n","- https://rentry.org/sdupdates#prompting **(PROMPT GOLDMINE)**\n","\n","## Galleries\n","- https://github.com/Maks-s/sd-akashic ([reddit](https://old.reddit.com/r/StableDiffusion/comments/wkq73p/i_made_a_list_of_useful_resources_for_prompt/))\n","- https://stablediffusion.fr/prompts\n","- https://promptbase.com/\n","- \n","\n","## Nice Read\n","- https://github.com/joelparkerhenderson/stable-diffusion-image-prompt-gallery/blob/main/stable-diffusion-image-prompt-gallery-book.md\n","- https://mpost.io/best-100-stable-diffusion-prompts-the-most-beautiful-ai-text-to-image-prompts/"],"metadata":{"id":"jQZBOFog7xDZ"}},{"cell_type":"markdown","source":["## 4Chan /g/\n","\n",">Models, Textual Inversion & Embeddings\n","\n","https://rentry.org/hdgrecipes\n","\n","https://civitai.com/\n","\n","https://rentry.org/embeddings\n","\n","https://rentry.org/lftbl\n","\n","https://rentry.org/sdmodels\n","\n",">Guides\n","\n","SD2: https://rentry.org/dummySD2\n","\n","NovelAi: https://rentry.org/sdg_FAQ\n","\n","Animation: https://rentry.org/AnimAnon | https://rentry.org/\n","AnimAnon-LoopbackWave\n","\n","Inpainting/Outpainting: https://rentry.org/drfar\n","\n","Upscaling images: https://rentry.org/sdupscale\n","\n","Textual inversion: https://rentry.org/textard\n","\n","Training: https://rentry.org/informal-training-guide\n","\n","Hypernetworks: https://rentry.org/hypernetwork4dumdums\n","\n","Dreambooth: https://rentry.org/sdg-link\n","\n","Safetensors: https://rentry.org/safetensorsguide\n","\n","\n",">Tools & Resources\n","\n","Index: https://pharmapsychotic.com/tools.html | https://rentry.org/sdgoldmine\n","\n","Artist Styles: https://rentry.org/sdg-link\n","\n","Prompt sharing: https://rentry.org/sdg-link\n","\n","Wildcard list: https://github.com/Lopyter/stable-soup-prompts\n","\n","img2img skeleton: https://app.posemy.art/\n","\n","Dataset: https://rentry.org/sdg-link\n","\n","/sdg/ prompts: https://rentry.org/54d9o\n"],"metadata":{"id":"HHWz1bTH9m_y"}}]}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment