+{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"TBRKMfqbIEDH"},"outputs":[],"source":["# Verify Google gave you GPU runtime and switch using dropdown above if not\n","!nvidia-smi -L\n","!nvidia-smi"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"XmBxfieaJM4K"},"outputs":[],"source":["# Set up colab paths\n","temp_colab_path = '/content/invokeai_temp_colab'\n","persist_colab_path = '/content/drive/MyDrive/invokeai_persist_colab'\n","\n","# Set if instance should be temporary or persistent\n","chosen_colab_path = temp_colab_path\n","\n","# Set up temporary storage if needed\n","if chosen_colab_path == temp_colab_path:\n"," import os\n"," if not os.path.exists(temp_colab_path):\n"," os.makedirs(temp_colab_path)\n","\n","# Mount and set up Google drive if needed/isn't already\n","if chosen_colab_path == persist_colab_path:\n"," import os\n"," from google.colab import drive\n"," if not os.path.exists(persist_colab_path):\n"," drive.mount('/content/drive')\n"," if not os.path.exists(persist_colab_path):\n"," os.makedirs(persist_colab_path)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"W3EC8CKJXpSU"},"outputs":[],"source":["# Sign up/accept terms/get tokens at https://huggingface.co/runwayml/stable-diffusion-v1-5 https://huggingface.co/runwayml/stable-diffusion-inpainting https://ngrok.com/\n","huggingface_token = 'HF_TOKEN_HERE'\n","ngrok_token = 'NGROK_TOKEN_HERE'"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"c40VE5vr0dWF"},"outputs":[],"source":["# Install python 3.9\n","!sudo apt-get update -y\n","!sudo apt-get install python3.9 python3-pip python3.9-distutils python3.9-dev libpython3.9-dev python3.9-venv -y\n","\n","# Change alternatives\n","!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1\n","!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2\n","\n","# Verify python version\n","!python --version\n","\n","# Update pip\n","%cd {chosen_colab_path}\n","!curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py\n","!python3 get-pip.py --force-reinstall\n","!python -m pip install --upgrade pip\n","!pip install --upgrade setuptools\n","\n","# Handle colab dependencies\n","!ln -s /usr/local/lib/python3.8/dist-packages/google /usr/local/lib/python3.9/dist-packages/google\n","!python3 -m pip install ipython ipython_genutils ipykernel jupyter_console prompt_toolkit httplib2 astor"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"e7U8CIkP3V2f"},"outputs":[],"source":["# Create InvokeAI root\n","invokeai_root = chosen_colab_path + '/invokeai'\n","import os\n","os.environ['INVOKEAI_ROOT'] = invokeai_root\n","if not os.path.exists(invokeai_root):\n"," os.makedirs(invokeai_root)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"XDrOUKU63uHj"},"outputs":[],"source":["# Create and prepare virtual environment\n","%cd {invokeai_root}\n","!python -m venv .venv --prompt InvokeAI\n","!source .venv/bin/activate; python -m pip install --upgrade pip\n","!source .venv/bin/activate; pip install InvokeAI[xformers] --use-pep517 --extra-index-url https://download.pytorch.org/whl/cu117"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"osE_8sgU5Mh7"},"outputs":[],"source":["# Download and configure models\n","%cd {invokeai_root}\n","import os\n","os.environ['HUGGING_FACE_HUB_TOKEN'] = huggingface_token\n","!source .venv/bin/activate; invokeai-configure --yes\n","!sed -i 's/--nsfw_checker/--no-nsfw_checker/' invokeai.init"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AitkguYp6IWB"},"outputs":[],"source":["# Import custom models\n","#%cd {invokeai_root}\n","#!cat /content/drive/MyDrive/stable_diffusion_weights/jenkinsmichpa/jenkinsmichpa.yaml >> configs/models.yaml"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R0CktNw3a6Jb"},"outputs":[],"source":["# Install and run NGROK proxy\n","%cd {chosen_colab_path}\n","!pip install pyngrok --quiet\n","from pyngrok import ngrok\n","ngrok.kill()\n","ngrok.set_auth_token(ngrok_token)\n","public_url = ngrok.connect(9090).public_url\n","print(f'InvokeAI Public URL: {public_url}')\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"yyOhF3zSYLse"},"outputs":[],"source":["# Start site\n","%cd {invokeai_root}\n","!source .venv/bin/activate; invokeai --web --host 0.0.0.0"]}],"metadata":{"accelerator":"GPU","colab":{"authorship_tag":"ABX9TyPP842mPTctu0dE0dJL4HAJ","mount_file_id":"1Igkry7gaXDupSdh4tYQQQZaD5Z6OU9Ul","provenance":[]},"gpuClass":"standard","kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
0 commit comments