{ "cells": [ { "cell_type": "markdown", "id": "d520cdce-6234-40b8-9a6d-c0d073249e62", "metadata": {}, "source": [ "**此代码适用于新镜像:192.168.204.22:5000/default-workspace/99280a9940ae44ca8f5892134386fddb/image:sd_final**" ] }, { "cell_type": "markdown", "id": "a48381fe", "metadata": {}, "source": [ "# 首次使用先复制镜像(左侧目录有sd就不用按这个):" ] }, { "cell_type": "code", "execution_count": null, "id": "145e099f", "metadata": { "tags": [] }, "outputs": [], "source": [ "#复制镜像\n", "!cp -r /sd /code\n", "!cp /t/lora/sd-models/131-half.safetensors /code/sd/models/Stable-diffusion\n", "!echo \"finish-copy\"\n", "#查看显卡\n", "!echo 你的GPU是:& nvidia-smi -L" ] }, { "cell_type": "markdown", "id": "ca9e8951-2c27-4241-b2dd-27ed20aa748f", "metadata": {}, "source": [ "# 30min定时关机脚本:(无限白嫖GPU):\n", "### **详细见**:https://github.com/2575044704/auto_shutdown" ] }, { "cell_type": "code", "execution_count": null, "id": "d2a91be9-3337-443f-b8e0-1617a2486ef3", "metadata": { "tags": [] }, "outputs": [], "source": [ "import subprocess\n", "try:\n", " process = subprocess.Popen([\"bash\", \"shutdown.sh\"])\n", " print(\"自动关机脚本已启动\")\n", "except Exception as e:\n", " print(f\"启动自动关机脚本失败,错误:{e}\")" ] }, { "cell_type": "markdown", "id": "9459c185", "metadata": {}, "source": [ "# SD启动:" ] }, { "cell_type": "code", "execution_count": null, "id": "84f9609a", "metadata": { "tags": [] }, "outputs": [], "source": [ "%cd /code/sd\n", "import os\n", "package_envs = [\n", " {\"env\": \"STABLE_DIFFUSION_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/stablediffusion\")},\n", " {\"env\": \"STABLE_DIFFUSION_XL_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_XL_REPO', \"https://gitcode.net/overbill1683/generative-models\")},\n", " {\"env\": \"K_DIFFUSION_REPO\", \"url\": os.environ.get('K_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/k-diffusion\")},\n", " {\"env\": \"CODEFORMER_REPO\", \"url\": os.environ.get('CODEFORMER_REPO', \"https://gitcode.net/overbill1683/CodeFormer\")},\n", " {\"env\": \"BLIP_REPO\", \"url\": os.environ.get('BLIP_REPO', \"https://gitcode.net/overbill1683/BLIP\")},\n", "]\n", "os.environ[\"PIP_INDEX_URL\"] = \"https://mirrors.aliyun.com/pypi/simple/\"\n", "for i in package_envs:\n", " os.environ[i[\"env\"]] = i[\"url\"]\n", " \n", "# 请记得填写ngrok token\n", "!python launch.py --ngrok=你的token --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test" ] }, { "cell_type": "markdown", "id": "9eeb5985", "metadata": {}, "source": [ "-------" ] }, { "cell_type": "markdown", "id": "9e26887f", "metadata": {}, "source": [ "# 下载模型,直接把模型下载地址粘贴进去\n", "# 支持的模型下载站:liblib.ai, tusiart.com, Huggingface镜像站\n", "# 不支持的:Civitai,\n", "## HUggingface镜像站:huggingface.sukaka.top\n", "## 必须先把SD停下来再执行代码!" ] }, { "cell_type": "code", "execution_count": null, "id": "7c3e8600", "metadata": {}, "outputs": [], "source": [ "# 下载 模型\n", "urls = ['https://huggingface.sukaka.top/datasets/ACCC1380/private-model/resolve/main/ba.safetensors']\n", "\n", "下载目录 = '/code/sd/models/Lora'\n", "\n", "文件名 = \"wodemoxing.safetensors\"\n", "# SD大模型目录 :/code/sd/models/Lora\n", "# Lora目录:/code/sd/models/Lora\n", "# VAE目录:/code/sd/models/VAE\n", "\n", "%cd {下载目录}\n", "for url in urls:\n", " !aria2c -x 16 -s 16 -c -k 1M --console-log-level=error \"{url}\" -o \"{文件名}\"\n", "%cd /code" ] }, { "cell_type": "code", "execution_count": null, "id": "6098be12", "metadata": {}, "outputs": [], "source": [ "## 安装常用插件,github如果连不上就多执行几次\n", "extensions = [\n", "\"https://gitcode.net/ranting8323/sd-webui-controlnet\",\n", "]\n", "%cd /code/sd\n", "\n", "for e in extensions:\n", " proxied_url = e\n", " !git -C \"extensions\" clone {proxied_url}" ] }, { "cell_type": "markdown", "id": "17062dc1-2083-41fb-9a67-5a9f623b1276", "metadata": {}, "source": [ "------------------" ] }, { "cell_type": "markdown", "id": "a69b680b-c87d-4219-9eec-d69baec9f2c9", "metadata": {}, "source": [ "# 下面代码是启动秋叶的Lora训练器:" ] }, { "cell_type": "markdown", "id": "0d89e635-77a2-4c18-b126-e914e30d8841", "metadata": {}, "source": [ "# 1.拉取lora训练文件(首次启动)(左侧有lora文件夹就不用拉取)" ] }, { "cell_type": "code", "execution_count": null, "id": "451c1e08-7eb0-4dab-92e2-6f7879f68c08", "metadata": { "tags": [] }, "outputs": [], "source": [ "!cp -r /t/lora/ /code" ] }, { "cell_type": "markdown", "id": "9f2ae3fa-1729-4a58-8e6f-92cfd1c12597", "metadata": {}, "source": [ "# 2. 启动Lora训练器" ] }, { "cell_type": "code", "execution_count": null, "id": "2f53478e-1788-45d1-9a12-a757f81edde5", "metadata": { "tags": [] }, "outputs": [], "source": [ "# 先配置ngrok再启动!!,启动后找到ngrok链接即可!\n", "import os\n", "%cd /code/lora\n", "!/code/lora/venv/bin/python gui.py --disable-dataset-tag-editor & ngrok http 28000 --authtoken=你的ngroktoken" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }