Last active
March 18, 2025 20:16
-
-
Save jonshipman/b17a3a66a0c2247dc001f84fa671b434 to your computer and use it in GitHub Desktop.
Colab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"gpuType":"T4","private_outputs":true,"authorship_tag":"ABX9TyMqVwMq9PSWBBB13V/GsEyW"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU"},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"OkVTPmSu2-yL","collapsed":true,"cellView":"form"},"outputs":[],"source":["from google.colab import drive\n","import os\n","import time\n","\n","root = \"/content\"\n","os.chdir(root)\n","\n","#@markdown #Stable Diffusion Runner\n","\n","drive.mount('/content/gdrive', force_remount=True)\n","\n","# Prevents Google Drive from sleeping/disconnecting\n","!while true; do nohup ls -la /content/gdrive/MyDrive >/dev/null 2>&1; sleep 5; done >/dev/null 2>&1 &\n","\n","os.environ[\"PYTORCH_CUDA_ALLOC_CONF\"] = \"max_split_size_mb:1024\"\n","os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n","\n","MODELS = \"/content/gdrive/MyDrive/stable-diffusion-runner/models\" #@param {type:\"string\"}\n","EXTENSIONS = \"/content/gdrive/MyDrive/stable-diffusion-runner/extensions\" #@param {type:\"string\"}\n","EMBEDDINGS = \"/content/gdrive/MyDrive/stable-diffusion-runner/embeddings\" #@param {type:\"string\"}\n","CONFIG = \"/content/gdrive/MyDrive/stable-diffusion-runner\" #@param {type:\"string\"}\n","NGROK = \"\" #@param {type:\"string\"}\n","\n","os.environ[\"MODELS\"] = str(MODELS)\n","os.environ[\"EXTENSIONS\"] = str(EXTENSIONS)\n","os.environ[\"EMBEDDINGS\"] = str(EMBEDDINGS)\n","os.environ[\"CONFIG\"] = str(CONFIG)\n","os.environ[\"NGROK\"] = str(NGROK)\n","os.environ[\"COMMANDLINE_ARGS\"] = \"--opt-sdp-attention --no-half-vae --enable-insecure-extension-access\"\n","\n","tmpdir = os.path.join(root, \"tmp\")\n","\n","if not NGROK:\n"," if os.path.exists(\"srv.txt\"):\n"," os.remove(\"srv.txt\")\n"," if not os.path.exists('/tools/node/bin/lt'):\n"," !npm install -g localtunnel\n","\n"," !nohup lt --port 7860 > srv.txt 2>&1 &\n"," print(\"\\n\\n\")\n"," lt_url=\"\"\n"," while len(lt_url) < 1:\n"," if os.path.isfile(\"srv.txt\"):\n"," with open(\"srv.txt\", 'r') as file:\n"," lt_url = file.read()\n"," lt_url = lt_url.replace(\"your url is: \", \"\").strip()\n"," time.sleep(1)\n"," print(lt_url)\n"," !curl https://loca.lt/mytunnelpassword\n"," print(\"\\n\\n\")\n","\n","directory_list = [tmpdir,str(MODELS),str(EXTENSIONS),str(EMBEDDINGS),str(CONFIG)]\n","for directory_name in directory_list:\n"," if not os.path.exists(directory_name):\n"," os.makedirs(directory_name)\n","\n","os.chdir(tmpdir)\n","\n","!apt install wget git python3 python3-venv libgl1 libglib2.0-0\n","\n","if not os.path.exists('./webui-user.sh'):\n"," !echo 'venv_dir=\"-\"' > ./webui-user.sh\n","\n","!wget -qN https://raw.githubusercontent.com/jonshipman/colab-sd-webui/master/webui.sh\n","\n","!bash webui.sh -f\n","\n"]},{"cell_type":"code","source":["import shutil\n","\n","#@markdown #Copies config files back to the runner directory.\n","\n","os.chdir(os.path.join(tmpdir, \"stable-diffusion-webui\"))\n","\n","if os.path.exists(str(CONFIG)):\n"," config_files = [\"styles.csv\" ,\"ui-config.json\" ,\"config.json\" ,\"cache.json\"]\n"," for cfile in config_files:\n"," cfile_path = os.path.join(str(CONFIG), cfile)\n"," if os.path.exists(cfile_path) and os.path.exists(cfile):\n"," os.remove(cfile_path)\n","\n"," if os.path.exists(cfile):\n"," shutil.copy(cfile, cfile_path)"],"metadata":{"id":"92m4grYWopGP","cellView":"form"},"execution_count":null,"outputs":[]}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment