Spaces:
Running
Running
Upload GPU.ipynb
Browse files- colab/GPU.ipynb +193 -0
colab/GPU.ipynb
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"attachments": {},
|
5 |
+
"cell_type": "markdown",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"**Links**<br>\n",
|
9 |
+
"Extensions API GitHub: https://github.com/SillyTavern/SillyTavern-extras/<br>\n",
|
10 |
+
"SillyTavern community Discord (support and discussion): https://discord.gg/sillytavern"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": null,
|
16 |
+
"metadata": {},
|
17 |
+
"outputs": [],
|
18 |
+
"source": [
|
19 |
+
"#@title <-- Tap this if you run on Mobile { display-mode: \"form\" }\n",
|
20 |
+
"#Taken from KoboldAI colab\n",
|
21 |
+
"%%html\n",
|
22 |
+
"<b>Press play on the audio player to keep the tab alive. (Uses only 13MB of data)</b><br/>\n",
|
23 |
+
"<audio src=\"https://henk.tech/colabkobold/silence.m4a\" controls>"
|
24 |
+
]
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"cell_type": "code",
|
28 |
+
"execution_count": null,
|
29 |
+
"metadata": {
|
30 |
+
"cellView": "form",
|
31 |
+
"id": "lVftocpwCoYw"
|
32 |
+
},
|
33 |
+
"outputs": [],
|
34 |
+
"source": [
|
35 |
+
"#@markdown (RECOMMENDED) Generates an API key for you to use with the API\n",
|
36 |
+
"secure = False #@param {type:\"boolean\"}\n",
|
37 |
+
"#@markdown Allows to run SillyTavern Extras on CPU (use if you're out of daily GPU allowance)\n",
|
38 |
+
"use_cpu = False #@param {type:\"boolean\"}\n",
|
39 |
+
"#@markdown Allows to run Stable Diffusion pipeline on CPU (slow!)\n",
|
40 |
+
"use_sd_cpu = False #@param {type:\"boolean\"}\n",
|
41 |
+
"#@markdown ***\n",
|
42 |
+
"#@markdown Enables the WebSearch module\n",
|
43 |
+
"extras_enable_websearch = True #@param {type:\"boolean\"}\n",
|
44 |
+
"#@markdown ***\n",
|
45 |
+
"#@markdown Loads the image captioning module\n",
|
46 |
+
"extras_enable_caption = True #@param {type:\"boolean\"}\n",
|
47 |
+
"captioning_model = \"Salesforce/blip-image-captioning-large\" #@param [ \"Salesforce/blip-image-captioning-large\", \"Salesforce/blip-image-captioning-base\" ]\n",
|
48 |
+
"#@markdown * Salesforce/blip-image-captioning-large - good base model\n",
|
49 |
+
"#@markdown * Salesforce/blip-image-captioning-base - slightly faster but less accurate\n",
|
50 |
+
"#@markdown ***\n",
|
51 |
+
"#@markdown Loads the sentiment classification model\n",
|
52 |
+
"extras_enable_classify = True #@param {type:\"boolean\"}\n",
|
53 |
+
"classification_model = \"nateraw/bert-base-uncased-emotion\" #@param [\"nateraw/bert-base-uncased-emotion\", \"joeddav/distilbert-base-uncased-go-emotions-student\"]\n",
|
54 |
+
"#@markdown * nateraw/bert-base-uncased-emotion = 6 supported emotions<br>\n",
|
55 |
+
"#@markdown * joeddav/distilbert-base-uncased-go-emotions-student = 28 supported emotions\n",
|
56 |
+
"#@markdown ***\n",
|
57 |
+
"#@markdown Loads the story summarization module\n",
|
58 |
+
"extras_enable_summarize = True #@param {type:\"boolean\"}\n",
|
59 |
+
"summarization_model = \"slauw87/bart_summarisation\" #@param [ \"slauw87/bart_summarisation\", \"Qiliang/bart-large-cnn-samsum-ChatGPT_v3\", \"Qiliang/bart-large-cnn-samsum-ElectrifAi_v10\", \"distilbart-xsum-12-3\" ]\n",
|
60 |
+
"#@markdown * slauw87/bart_summarisation - general purpose summarization model\n",
|
61 |
+
"#@markdown * Qiliang/bart-large-cnn-samsum-ChatGPT_v3 - summarization model optimized for chats\n",
|
62 |
+
"#@markdown * Qiliang/bart-large-cnn-samsum-ElectrifAi_v10 - nice results so far, but still being evaluated\n",
|
63 |
+
"#@markdown * distilbart-xsum-12-3 - faster, but pretty basic alternative\n",
|
64 |
+
"#@markdown ***\n",
|
65 |
+
"#@markdown Enables Silero text-to-speech module\n",
|
66 |
+
"extras_enable_silero_tts = True #@param {type:\"boolean\"}\n",
|
67 |
+
"#@markdown Enables Microsoft Edge text-to-speech module\n",
|
68 |
+
"extras_enable_edge_tts = True #@param {type:\"boolean\"}\n",
|
69 |
+
"#@markdown Enables RVC module\n",
|
70 |
+
"extras_enable_rvc = False #@param {type:\"boolean\"}\n",
|
71 |
+
"#@markdown ***\n",
|
72 |
+
"#@markdown Enables Whisper speech recognition module\n",
|
73 |
+
"extras_enable_whisper_stt = True #@param {type:\"boolean\"}\n",
|
74 |
+
"whisper_model = \"base.en\" #@param [ \"tiny.en\", \"base.en\", \"small.en\", \"medium.en\", \"tiny\", \"base\", \"small\", \"medium\", \"large\" ]\n",
|
75 |
+
"#@markdown There are five model sizes, four with English-only versions, offering speed and accuracy tradeoffs.\n",
|
76 |
+
"#@markdown The .en models for English-only applications tend to perform better, especially for the tiny.en and base.en models.\n",
|
77 |
+
"#@markdown ***\n",
|
78 |
+
"#@markdown Enables SD picture generation\n",
|
79 |
+
"extras_enable_sd = True #@param {type:\"boolean\"}\n",
|
80 |
+
"sd_model = \"ckpt/anything-v4.5-vae-swapped\" #@param [ \"ckpt/anything-v4.5-vae-swapped\", \"hakurei/waifu-diffusion\", \"philz1337/clarity\", \"prompthero/openjourney\", \"ckpt/sd15\", \"stabilityai/stable-diffusion-2-1-base\" ]\n",
|
81 |
+
"#@markdown * ckpt/anything-v4.5-vae-swapped - anime style model\n",
|
82 |
+
"#@markdown * hakurei/waifu-diffusion - anime style model\n",
|
83 |
+
"#@markdown * philz1337/clarity - realistic style model\n",
|
84 |
+
"#@markdown * prompthero/openjourney - midjourney style model\n",
|
85 |
+
"#@markdown * ckpt/sd15 - base SD 1.5\n",
|
86 |
+
"#@markdown * stabilityai/stable-diffusion-2-1-base - base SD 2.1\n",
|
87 |
+
"#@markdown ***\n",
|
88 |
+
"#@markdown Enables ChromaDB module\n",
|
89 |
+
"extras_enable_chromadb = True #@param {type:\"boolean\"}\n",
|
90 |
+
"\n",
|
91 |
+
"import subprocess\n",
|
92 |
+
"import secrets\n",
|
93 |
+
"\n",
|
94 |
+
"# ---\n",
|
95 |
+
"# SillyTavern extras\n",
|
96 |
+
"extras_url = '(disabled)'\n",
|
97 |
+
"params = []\n",
|
98 |
+
"if use_cpu:\n",
|
99 |
+
" params.append('--cpu')\n",
|
100 |
+
"if use_sd_cpu:\n",
|
101 |
+
" params.append('--sd-cpu')\n",
|
102 |
+
"if secure:\n",
|
103 |
+
" params.append('--secure')\n",
|
104 |
+
"params.append('--share')\n",
|
105 |
+
"modules = []\n",
|
106 |
+
"\n",
|
107 |
+
"if extras_enable_caption:\n",
|
108 |
+
" modules.append('caption')\n",
|
109 |
+
"if extras_enable_summarize:\n",
|
110 |
+
" modules.append('summarize')\n",
|
111 |
+
"if extras_enable_classify:\n",
|
112 |
+
" modules.append('classify')\n",
|
113 |
+
"if extras_enable_sd:\n",
|
114 |
+
" modules.append('sd')\n",
|
115 |
+
"if extras_enable_silero_tts:\n",
|
116 |
+
" modules.append('silero-tts')\n",
|
117 |
+
"if extras_enable_edge_tts:\n",
|
118 |
+
" modules.append('edge-tts')\n",
|
119 |
+
"if extras_enable_chromadb:\n",
|
120 |
+
" modules.append('chromadb')\n",
|
121 |
+
"if extras_enable_whisper_stt:\n",
|
122 |
+
" modules.append('whisper-stt')\n",
|
123 |
+
" params.append(f'--stt-whisper-model-path={whisper_model}')\n",
|
124 |
+
"if extras_enable_rvc:\n",
|
125 |
+
" modules.append('rvc')\n",
|
126 |
+
" params.append('--max-content-length=2000')\n",
|
127 |
+
" params.append('--rvc-save-file')\n",
|
128 |
+
"\n",
|
129 |
+
"\n",
|
130 |
+
"if extras_enable_websearch:\n",
|
131 |
+
" print(\"Enabling WebSearch module\")\n",
|
132 |
+
" modules.append('websearch')\n",
|
133 |
+
" !apt update\n",
|
134 |
+
" !apt install -y chromium-chromedriver\n",
|
135 |
+
"\n",
|
136 |
+
"params.append(f'--classification-model={classification_model}')\n",
|
137 |
+
"params.append(f'--summarization-model={summarization_model}')\n",
|
138 |
+
"params.append(f'--captioning-model={captioning_model}')\n",
|
139 |
+
"params.append(f'--sd-model={sd_model}')\n",
|
140 |
+
"params.append(f'--enable-modules={\",\".join(modules)}')\n",
|
141 |
+
"\n",
|
142 |
+
"\n",
|
143 |
+
"%cd /\n",
|
144 |
+
"!git clone https://github.com/SillyTavern/SillyTavern-extras\n",
|
145 |
+
"%cd /SillyTavern-extras\n",
|
146 |
+
"!git clone https://github.com/Cohee1207/tts_samples\n",
|
147 |
+
"!npm install -g localtunnel\n",
|
148 |
+
"%pip install -r requirements.txt\n",
|
149 |
+
"!wget https://github.com/cloudflare/cloudflared/releases/download/2023.5.0/cloudflared-linux-amd64 -O /tmp/cloudflared-linux-amd64\n",
|
150 |
+
"!chmod +x /tmp/cloudflared-linux-amd64\n",
|
151 |
+
"\n",
|
152 |
+
"if extras_enable_rvc:\n",
|
153 |
+
" print(\"Installing RVC requirements\")\n",
|
154 |
+
" %pip install -r requirements-rvc.txt\n",
|
155 |
+
"\n",
|
156 |
+
"# Generate a random API key\n",
|
157 |
+
"api_key = secrets.token_hex(5)\n",
|
158 |
+
"\n",
|
159 |
+
"# Write the API key to api_key.txt\n",
|
160 |
+
"with open('./api_key.txt', 'w') as f:\n",
|
161 |
+
" f.write(api_key)\n",
|
162 |
+
"print(f\"API Key generated: {api_key}\")\n",
|
163 |
+
"\n",
|
164 |
+
"cmd = f\"python server.py {' '.join(params)}\"\n",
|
165 |
+
"print(cmd)\n",
|
166 |
+
"extras_process = subprocess.Popen(\n",
|
167 |
+
" cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd='/SillyTavern-extras', shell=True)\n",
|
168 |
+
"print('processId:', extras_process.pid)\n",
|
169 |
+
"while True:\n",
|
170 |
+
" line = extras_process.stdout.readline().decode().strip()\n",
|
171 |
+
" if line != None and line != '':\n",
|
172 |
+
" print(line)\n"
|
173 |
+
]
|
174 |
+
}
|
175 |
+
],
|
176 |
+
"metadata": {
|
177 |
+
"accelerator": "GPU",
|
178 |
+
"colab": {
|
179 |
+
"private_outputs": true,
|
180 |
+
"provenance": []
|
181 |
+
},
|
182 |
+
"gpuClass": "standard",
|
183 |
+
"kernelspec": {
|
184 |
+
"display_name": "Python 3",
|
185 |
+
"name": "python3"
|
186 |
+
},
|
187 |
+
"language_info": {
|
188 |
+
"name": "python"
|
189 |
+
}
|
190 |
+
},
|
191 |
+
"nbformat": 4,
|
192 |
+
"nbformat_minor": 0
|
193 |
+
}
|