Instructions:
- Execute each cell in order to mount a Dream bot and create images from text.
- Once cells 1-8 were run correctly you’ll be executing a terminal in cell #9, you’ll need to enter
python scripts/dream.py
command to run Dream bot. - After launching dream bot, you’ll see:
Dream >
in terminal.
Insert a command, eg.Dream > Astronaut floating in a distant galaxy
, or type-h
for help. - After completion you’ll see your generated images in path
stable-diffusion/outputs/img-samples/
, you can also show last generated images in cell #10. - To quit Dream bot use
q
command.
Note: It takes some time to load, but after installing all dependencies you can use the bot all time you want while colab instance is up.
Requirements: For this notebook to work you need to have Stable-Diffusion-v-1-4 stored in your Google Drive, it will be needed in cell #7
For more details visit Github repository: invoke-ai/InvokeAI
In [ ]:
#@title 1. Check current GPU assigned
!nvidia-smi -L
!nvidia-smi
In [ ]:
#@title 2. Download stable-diffusion Repository
from os.path import exists
!git clone --quiet https://github.com/invoke-ai/InvokeAI.git # Original repo
%cd /content/InvokeAI/
!git checkout --quiet tags/v2.0.0
In [ ]:
#@title 3. Install dependencies
import gc
!wget https://raw.githubusercontent.com/invoke-ai/InvokeAI/development/requirements.txt
!wget https://raw.githubusercontent.com/invoke-ai/InvokeAI/development/requirements-lin-win-colab-CUDA.txt
!pip install colab-xterm
!pip install -r requirements-lin-win-colab-CUDA.txt
!pip install clean-fid torchtext
!pip install transformers
gc.collect()
In [ ]:
#@title 4. Restart Runtime
exit()
In [ ]:
#@title 5. Load small ML models required
import gc
%cd /content/InvokeAI/
!python scripts/preload_models.py
gc.collect()
In [ ]:
#@title 6. Mount google Drive
from google.colab import drive
drive.mount('/content/drive')
In [ ]:
#@title 7. Drive Path to model
#@markdown Path should start with /content/drive/path-to-your-file
#@markdown Note: Model should be downloaded from https://huggingface.co
#@markdown Lastest release: [Stable-Diffusion-v-1-4](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original)
from os.path import exists
model_path = "" #@param {type:"string"}
if exists(model_path):
print("✅ Valid directory")
else:
print("❌ File doesn't exist")
In [ ]:
#@title 8. Symlink to model
from os.path import exists
import os
# Folder creation if it doesn't exist
if exists("/content/InvokeAI/models/ldm/stable-diffusion-v1"):
print("❗ Dir stable-diffusion-v1 already exists")
else:
%mkdir /content/InvokeAI/models/ldm/stable-diffusion-v1
print("✅ Dir stable-diffusion-v1 created")
# Symbolic link if it doesn't exist
if exists("/content/InvokeAI/models/ldm/stable-diffusion-v1/model.ckpt"):
print("❗ Symlink already created")
else:
src = model_path
dst = '/content/InvokeAI/models/ldm/stable-diffusion-v1/model.ckpt'
os.symlink(src, dst)
print("✅ Symbolic link created successfully")
In [ ]:
#@title 9. Run Terminal and Execute Dream bot
#@markdown Steps:
#@markdown 1. Execute command `python scripts/invoke.py` to run InvokeAI.
#@markdown 2. After initialized you'll see `Dream>` line.
#@markdown 3. Example text: `Astronaut floating in a distant galaxy`
#@markdown 4. To quit Dream bot use: `q` command.
%load_ext colabxterm
%xterm
gc.collect()
In [ ]:
#@title 10. Show the last 15 generated images
import glob
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline
images = []
for img_path in sorted(glob.glob('/content/InvokeAI/outputs/img-samples/*.png'), reverse=True):
images.append(mpimg.imread(img_path))
images = images[:15]
plt.figure(figsize=(20,10))
columns = 5
for i, image in enumerate(images):
ax = plt.subplot(len(images) / columns + 1, columns, i + 1)
ax.axes.xaxis.set_visible(False)
ax.axes.yaxis.set_visible(False)
ax.axis('off')
plt.imshow(image)
gc.collect()
Copyright © Code Fetcher 2022