mirror of
https://github.com/SillyTavern/SillyTavern-Extras.git
synced 2026-03-04 19:10:05 +00:00
291 lines
13 KiB
Plaintext
291 lines
13 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "d-Yihz3hAb2E"
|
|
},
|
|
"source": [
|
|
"https://colab.research.google.com/github/SillyLossy/TavernAI-extras/blob/main/colab/GPU.ipynb<br>\n",
|
|
"\n",
|
|
"Works with:<br>\n",
|
|
"KoboldAI https://github.com/KoboldAI/KoboldAI-Client<br>\n",
|
|
"Pygmalion https://huggingface.co/PygmalionAI/<br>\n",
|
|
"<br>\n",
|
|
"**Links**<br>\n",
|
|
"Cohee's TavernAI fork Github https://github.com/SillyLossy/TavernAI<br>\n",
|
|
"Cohee's TavernAI Extras Github https://github.com/SillyLossy/TavernAI-extras/\n",
|
|
"TavernAI Discord https://discord.gg/zmK2gmr45t<br>\n",
|
|
"TavernAI Boosty https://boosty.to/tavernai<br>\n",
|
|
"Questions? Hit me up on Discord: Cohee#1207\n",
|
|
"<pre>\n",
|
|
" Tavern.AI/ \\ / ^ ^ ^ ^ ~~~~ ^ \\ / ^ ^ ^ ^/ ^ ^ \\/^ ^ \\\n",
|
|
" /^ ^\\ ^ ^ ^ ^ ^ ~~ ^ \\ / ^ ^ ^ / ^ ^ ^/ ^ ^ \\\n",
|
|
" /^ ^ ^\\^ ^ ^ ^ _||____ ^ \\ / ^ ^ ^ / / ^ ^ ^ \\\n",
|
|
" /\\ /\\ /\\ ^ \\ /\\ /\\ /\\\\\\\\\\\\\\\\ ^ \\ ^ /\\ /\\ /\\ /\\ /\\ /\\ ^ ^ ^/\\\n",
|
|
"//\\\\/\\\\/\\\\ ^ \\//\\\\/\\\\ /__\\\\\\\\\\\\\\\\ _, \\ //\\\\/\\\\/\\\\ //\\\\/\\\\/\\\\ ^ ^ //\\\\\n",
|
|
"//\\\\/\\\\/\\\\ //\\\\/\\\\ |__|_|_|__| \\__, //\\\\/\\\\/\\\\ //\\\\/\\\\/\\\\ ///\\\\\\\n",
|
|
" || || (@^◡^)(≖ ‸ ≖*) ( ←_← )\\| /| /\\ \\ヽ(°ㅂ°╬) |( Ψ▼ー▼)∈ (O_O; ) |||\n",
|
|
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~ \n",
|
|
"</pre>\n",
|
|
"**Launch Instructions**<br>\n",
|
|
"1. Click the launch button.\n",
|
|
"2. Wait for the environment and model to load\n",
|
|
"3. After initialization, a TavernAI link will appear\n",
|
|
"\n",
|
|
"**Faq**<br>\n",
|
|
"* Q: I do not get a TavernAI link\n",
|
|
"* A: It seems the localtunnel service is currently down, so the TavernAI link is unavailable. Need to wait for it to start working again."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "hCpoIHxYcDGs"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#@title <-- Tap this if you play on Mobile { display-mode: \"form\" }\n",
|
|
"#Taken from KoboldAI colab\n",
|
|
"%%html\n",
|
|
"<b>Press play on the music player to keep the tab alive, then start TavernAI below (Uses only 13MB of data)</b><br/>\n",
|
|
"<audio src=\"https://henk.tech/colabkobold/silence.m4a\" controls>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"cellView": "form",
|
|
"id": "hps3qtPLFNBb"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#@title <b>TavernAI</b>\n",
|
|
"#@markdown <- Click For Start (≖ ‸ ≖ ✿)\n",
|
|
"\n",
|
|
"Model = \"Pygmalion 6B\" #@param [ \"Pygmalion 6B\", \"Pygmalion 6B Dev\"] {allow-input: true}\n",
|
|
"Version = \"Official\" \n",
|
|
"KoboldAI_Provider = \"Cloudflare\" #@param [\"Localtunnel\", \"Cloudflare\"]\n",
|
|
"use_google_drive = False #@param {type:\"boolean\"}\n",
|
|
"extras_enable_captioning = True #@param {type:\"boolean\"}\n",
|
|
"Captions_Model = \"Salesforce/blip-image-captioning-large\" #@param [ \"Salesforce/blip-image-captioning-large\", \"Salesforce/blip-image-captioning-base\", \"microsoft/git-large-r-textcaps\" ]\n",
|
|
"#@markdown * Salesforce/blip-image-captioning-large - good base model\n",
|
|
"#@markdown * Salesforce/blip-image-captioning-base - slightly faster but less accurate\n",
|
|
"#@markdown * microsoft/git-large-r-textcaps - works best for pictures with text (memes), but slightly worse for cartoon/anime drawings\n",
|
|
"extras_enable_emotions = True #@param {type:\"boolean\"}\n",
|
|
"Emotions_Model = \"bhadresh-savani/distilbert-base-uncased-emotion\" #@param [\"bhadresh-savani/distilbert-base-uncased-emotion\", \"joeddav/distilbert-base-uncased-go-emotions-student\"]\n",
|
|
"#@markdown * bhadresh-savani/distilbert-base-uncased-emotion = 6 supported emotions<br>\n",
|
|
"#@markdown * joeddav/distilbert-base-uncased-go-emotions-student = 28 supported emotions\n",
|
|
"extras_enable_memory = True #@param {type:\"boolean\"}\n",
|
|
"Memory_Model = \"Qiliang/bart-large-cnn-samsum-ChatGPT_v3\" #@param [ \"Qiliang/bart-large-cnn-samsum-ChatGPT_v3\", \"Qiliang/bart-large-cnn-samsum-ElectrifAi_v10\", \"distilbart-xsum-12-3\" ]\n",
|
|
"#@markdown * Qiliang/bart-large-cnn-samsum-ChatGPT_v3 - summarization model optimized for chats\n",
|
|
"#@markdown * Qiliang/bart-large-cnn-samsum-ElectrifAi_v10 - nice results so far, but still being evaluated\n",
|
|
"#@markdown * distilbart-xsum-12-3 - faster, but pretty basic alternative\n",
|
|
"\n",
|
|
"Provider = KoboldAI_Provider\n",
|
|
"!nvidia-smi\n",
|
|
"import subprocess\n",
|
|
"import time\n",
|
|
"import sys\n",
|
|
"import os\n",
|
|
"import threading\n",
|
|
"import shutil\n",
|
|
"from google.colab import drive\n",
|
|
"\n",
|
|
" \n",
|
|
"if use_google_drive:\n",
|
|
" drive.mount('/content/drive/')\n",
|
|
" if not os.path.exists(\"/content/drive/MyDrive/TavernAI/\"):\n",
|
|
" os.mkdir(\"/content/drive/MyDrive/TavernAI/\")\n",
|
|
" if not os.path.exists(\"/content/drive/MyDrive/TavernAI/characters/\"):\n",
|
|
" os.mkdir(\"/content/drive/MyDrive/TavernAI/characters/\")\n",
|
|
" if not os.path.exists(\"/content/drive/MyDrive/TavernAI/chats/\"):\n",
|
|
" os.mkdir(\"/content/drive/MyDrive/TavernAI/chats/\")\n",
|
|
"else:\n",
|
|
" if not os.path.exists(\"/content/drive\"):\n",
|
|
" os.mkdir(\"/content/drive\")\n",
|
|
" if not os.path.exists(\"/content/drive/MyDrive/\"):\n",
|
|
" os.mkdir(\"/content/drive/MyDrive/\")\n",
|
|
"\n",
|
|
"def copy_characters(use_google_drive=False):\n",
|
|
" if not use_google_drive:\n",
|
|
" return\n",
|
|
" \n",
|
|
" src_folder = \"/TavernAIColab/public/characters\"\n",
|
|
" dst_folder = \"/content/drive/MyDrive/TavernAI/characters\"\n",
|
|
"\n",
|
|
" for filename in os.listdir(src_folder):\n",
|
|
" src_file = os.path.join(src_folder, filename)\n",
|
|
" dst_file = os.path.join(dst_folder, filename)\n",
|
|
"\n",
|
|
" if os.path.exists(dst_file):\n",
|
|
" print(f\"{dst_file} already exists. Skipping...\")\n",
|
|
" continue\n",
|
|
"\n",
|
|
" shutil.copy(src_file, dst_folder)\n",
|
|
" print(f\"{src_file} copied to {dst_folder}\")\n",
|
|
"Revision = \"\"\n",
|
|
"\n",
|
|
"if Model == \"Pygmalion 6B\":\n",
|
|
" Model = \"PygmalionAI/pygmalion-6b\"\n",
|
|
" path = \"\"\n",
|
|
" download = \"\"\n",
|
|
" Version = \"United\"\n",
|
|
"elif Model == \"Pygmalion 6B Dev\":\n",
|
|
" Model = \"PygmalionAI/pygmalion-6b\"\n",
|
|
" Revision = \"--revision dev\"\n",
|
|
" path = \"\"\n",
|
|
" Version = \"United\"\n",
|
|
" download = \"\"\n",
|
|
"\n",
|
|
"if Provider == \"Localtunnel\":\n",
|
|
" tunnel = \"--localtunnel yes\"\n",
|
|
"else:\n",
|
|
" tunnel = \"\"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"#Henk's KoboldAI script\n",
|
|
"!wget https://koboldai.org/ckds && chmod +x ckds\n",
|
|
"!./ckds --init only\n",
|
|
"if Provider == \"Localtunnel\":\n",
|
|
" p = subprocess.Popen(['/content/ckds', '--model', Model, '--localtunnel', 'yes'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
|
"else:\n",
|
|
" p = subprocess.Popen(['/content/ckds', '--model', Model], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
|
"\n",
|
|
"\n",
|
|
"#Do not repeat! Tricks performed by a professional!\n",
|
|
"url = ''\n",
|
|
"while True:\n",
|
|
" line = p.stdout.readline().decode().strip()\n",
|
|
" if \"KoboldAI has finished loading and is available at the following link: \" in line:\n",
|
|
" print(line)\n",
|
|
" url = line.split(\"KoboldAI has finished loading and is available at the following link: \")[1]\n",
|
|
" print(url)\n",
|
|
" break\n",
|
|
" if \"KoboldAI has finished loading and is available at the following link for UI 1: \" in line:\n",
|
|
" print(line)\n",
|
|
" url = line.split(\"KoboldAI has finished loading and is available at the following link for UI 1: \")[1]\n",
|
|
" print(url)\n",
|
|
" break\n",
|
|
" if not line:\n",
|
|
" break\n",
|
|
" print(line)\n",
|
|
" if \"INIT\" in line and \"Transformers\" in line:\n",
|
|
" print(\"Model loading... (It will take 2 - 5 minutes)\")\n",
|
|
"\n",
|
|
"params = []\n",
|
|
"\n",
|
|
"params.append('--cpu')\n",
|
|
"\n",
|
|
"ExtrasModules = []\n",
|
|
"\n",
|
|
"if (extras_enable_captioning):\n",
|
|
" ExtrasModules.append('caption')\n",
|
|
"\n",
|
|
"if (extras_enable_memory):\n",
|
|
" ExtrasModules.append('summarize')\n",
|
|
"\n",
|
|
"if (extras_enable_emotions):\n",
|
|
" ExtrasModules.append('classify')\n",
|
|
"\n",
|
|
"params.append(f'--classification-model={Emotions_Model}')\n",
|
|
"params.append(f'--summarization-model={Memory_Model}')\n",
|
|
"params.append(f'--captioning-model={Captions_Model}')\n",
|
|
"params.append(f'--enable-modules={\",\".join(ExtrasModules)}')\n",
|
|
"\n",
|
|
"#TavernAI extras\n",
|
|
"%cd /\n",
|
|
"!git clone https://github.com/SillyLossy/TavernAI-extras\n",
|
|
"%cd TavernAI-extras\n",
|
|
"!pip install -r requirements.txt\n",
|
|
"!pip install tensorflow==2.11\n",
|
|
"cmd = f\"python server.py {' '.join(params)}\"\n",
|
|
"print(cmd)\n",
|
|
"\n",
|
|
"extras_process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd='/TavernAI-extras', shell=True)\n",
|
|
"print('processId:', extras_process.pid)\n",
|
|
"\n",
|
|
"while True:\n",
|
|
" line = extras_process.stdout.readline().decode().strip()\n",
|
|
" if \"Running on \" in line:\n",
|
|
" break\n",
|
|
" if not line:\n",
|
|
" print('breaking on line')\n",
|
|
" break\n",
|
|
" print(line)\n",
|
|
"\n",
|
|
"subprocess.call('nohup lt --port 5100 > ./extras.out 2> ./extras.err &', shell=True)\n",
|
|
"print('Waiting for lt init...')\n",
|
|
"time.sleep(5)\n",
|
|
"\n",
|
|
"while True:\n",
|
|
" if (os.path.getsize('./extras.out') > 0):\n",
|
|
" with open('./extras.out', 'r') as f:\n",
|
|
" lines = f.readlines()\n",
|
|
" for x in range(len(lines)):\n",
|
|
" if ('your url is: ' in lines[x]):\n",
|
|
" print('TavernAI Extensions URL:')\n",
|
|
" extras_url = lines[x].split('your url is: ')[1]\n",
|
|
" print(extras_url)\n",
|
|
" break\n",
|
|
" if (os.path.getsize('./extras.err') > 0):\n",
|
|
" with open('./extras.err', 'r') as f:\n",
|
|
" print(f.readlines())\n",
|
|
" break\n",
|
|
"\n",
|
|
"#TavernAI\n",
|
|
"%cd /\n",
|
|
"!curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash\n",
|
|
"!nvm install 19.1.0\n",
|
|
"!nvm use 19.1.0\n",
|
|
"!node -v\n",
|
|
"!git clone -b dev https://github.com/SillyLossy/TavernAI\n",
|
|
"copy_characters(use_google_drive)\n",
|
|
"%cd TavernAIColab\n",
|
|
"!npm install\n",
|
|
"time.sleep(1)\n",
|
|
"%env colab=2\n",
|
|
"%env colaburl=$url\n",
|
|
"if use_google_drive:\n",
|
|
" %env googledrive=2\n",
|
|
"!nohup node server.js &\n",
|
|
"time.sleep(3)\n",
|
|
"print('KoboldAI LINK:')\n",
|
|
"print(url)\n",
|
|
"print('')\n",
|
|
"print('### TavernAI Extensions LINK ###')\n",
|
|
"print(extras_url)\n",
|
|
"print('')\n",
|
|
"print('###TavernAI LINK###')\n",
|
|
"!lt --port 8000\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"accelerator": "GPU",
|
|
"colab": {
|
|
"provenance": []
|
|
},
|
|
"gpuClass": "standard",
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.10.10"
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "9065d3a2a892c149b184b03d80719cad0a4af14f664fd4ada793b0c083136e40"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|