Spaces:
Runtime error
Runtime error
Initial Commit
Browse files
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Copy of Colab-TextGen-GPU.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/121BbV9KobFpXXP1VU__yse9FKZoqv5-T
|
8 |
+
|
9 |
+
# oobabooga/text-generation-webui
|
10 |
+
|
11 |
+
After running both cells, a public gradio URL will appear at the bottom in a few minutes. You can optionally generate an API link.
|
12 |
+
|
13 |
+
* Project page: https://github.com/oobabooga/text-generation-webui
|
14 |
+
* Gradio server status: https://status.gradio.app/
|
15 |
+
"""
|
16 |
+
|
17 |
+
# Commented out IPython magic to ensure Python compatibility.
|
18 |
+
# #@title 1. Keep this tab alive to prevent Colab from disconnecting you { display-mode: "form" }
|
19 |
+
#
|
20 |
+
# #@markdown Press play on the music player that will appear below:
|
21 |
+
# %%html
|
22 |
+
# <audio src="https://oobabooga.github.io/silence.m4a" controls>
|
23 |
+
|
24 |
+
# Commented out IPython magic to ensure Python compatibility.
|
25 |
+
#@title 2. Launch the web UI
|
26 |
+
|
27 |
+
#@markdown If unsure about the branch, write "main" or leave it blank.
|
28 |
+
|
29 |
+
import torch
|
30 |
+
from pathlib import Path
|
31 |
+
|
32 |
+
if Path.cwd().name != 'text-generation-webui':
|
33 |
+
print("Installing the webui...")
|
34 |
+
|
35 |
+
!git clone https://github.com/oobabooga/text-generation-webui
|
36 |
+
# %cd text-generation-webui
|
37 |
+
|
38 |
+
torver = torch.__version__
|
39 |
+
print(f"TORCH: {torver}")
|
40 |
+
is_cuda118 = '+cu118' in torver # 2.1.0+cu118
|
41 |
+
is_cuda117 = '+cu117' in torver # 2.0.1+cu117
|
42 |
+
|
43 |
+
textgen_requirements = open('requirements.txt').read().splitlines()
|
44 |
+
if is_cuda117:
|
45 |
+
textgen_requirements = [req.replace('+cu121', '+cu117').replace('+cu122', '+cu117').replace('torch2.1', 'torch2.0') for req in textgen_requirements]
|
46 |
+
elif is_cuda118:
|
47 |
+
textgen_requirements = [req.replace('+cu121', '+cu118').replace('+cu122', '+cu118') for req in textgen_requirements]
|
48 |
+
with open('temp_requirements.txt', 'w') as file:
|
49 |
+
file.write('\n'.join(textgen_requirements))
|
50 |
+
|
51 |
+
!pip install -r extensions/openai/requirements.txt --upgrade
|
52 |
+
!pip install -r temp_requirements.txt --upgrade
|
53 |
+
|
54 |
+
print("\033[1;32;1m\n --> If you see a warning about \"previously imported packages\", just ignore it.\033[0;37;0m")
|
55 |
+
print("\033[1;32;1m\n --> There is no need to restart the runtime.\n\033[0;37;0m")
|
56 |
+
|
57 |
+
try:
|
58 |
+
import flash_attn
|
59 |
+
except:
|
60 |
+
!pip uninstall -y flash_attn
|
61 |
+
|
62 |
+
# Parameters
|
63 |
+
model_url = "https://huggingface.co/TheBloke/OpenHermes-2.5-Mistral-7B-16k-GGUF" #@param {type:"string"}
|
64 |
+
branch = "main" #@param {type:"string"}
|
65 |
+
command_line_flags = "--n-gpu-layers 128 --load-in-4bit --use_double_quant" #@param {type:"string"}
|
66 |
+
api = False #@param {type:"boolean"}
|
67 |
+
|
68 |
+
if api:
|
69 |
+
for param in ['--api', '--public-api']:
|
70 |
+
if param not in command_line_flags:
|
71 |
+
command_line_flags += f" {param}"
|
72 |
+
|
73 |
+
model_url = model_url.strip()
|
74 |
+
if model_url != "":
|
75 |
+
if not model_url.startswith('http'):
|
76 |
+
model_url = 'https://huggingface.co/' + model_url
|
77 |
+
|
78 |
+
# Download the model
|
79 |
+
url_parts = model_url.strip('/').strip().split('/')
|
80 |
+
output_folder = f"{url_parts[-2]}_{url_parts[-1]}"
|
81 |
+
branch = branch.strip('"\' ')
|
82 |
+
if branch.strip() not in ['', 'main']:
|
83 |
+
output_folder += f"_{branch}"
|
84 |
+
!python download-model.py {model_url} --branch {branch}
|
85 |
+
else:
|
86 |
+
!python download-model.py {model_url}
|
87 |
+
else:
|
88 |
+
output_folder = ""
|
89 |
+
|
90 |
+
# Start the web UI
|
91 |
+
cmd = f"python server.py --share"
|
92 |
+
if output_folder != "":
|
93 |
+
cmd += f" --model {output_folder}"
|
94 |
+
cmd += f" {command_line_flags}"
|
95 |
+
print(cmd)
|
96 |
+
!$cmd
|