Skip to content

Commit 63c5a13

Browse files
author
Alexander Hristov Hristov
authored
Merge branch 'main' into main
2 parents 683556f + 7ab45fb commit 63c5a13

File tree

10 files changed

+159
-82
lines changed

10 files changed

+159
-82
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ko_fi: oobabooga

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Its goal is to become the [AUTOMATIC1111/stable-diffusion-webui](https://github.
2727
* [FlexGen offload](https://github.com/oobabooga/text-generation-webui/wiki/FlexGen).
2828
* [DeepSpeed ZeRO-3 offload](https://github.com/oobabooga/text-generation-webui/wiki/DeepSpeed).
2929
* Get responses via API, [with](https://github.com/oobabooga/text-generation-webui/blob/main/api-example-streaming.py) or [without](https://github.com/oobabooga/text-generation-webui/blob/main/api-example.py) streaming.
30-
* [Supports the LLaMA model](https://github.com/oobabooga/text-generation-webui/wiki/LLaMA-model).
30+
* [Supports the LLaMA model, including 4-bit mode](https://github.com/oobabooga/text-generation-webui/wiki/LLaMA-model).
3131
* [Supports the RWKV model](https://github.com/oobabooga/text-generation-webui/wiki/RWKV-model).
3232
* Supports softprompts.
3333
* [Supports extensions](https://github.com/oobabooga/text-generation-webui/wiki/Extensions).
@@ -60,11 +60,13 @@ pip3 install torch torchvision torchaudio --extra-index-url https://download.pyt
6060
conda install pytorch torchvision torchaudio git -c pytorch
6161
```
6262

63+
See also: [Installation instructions for human beings](https://github.com/oobabooga/text-generation-webui/wiki/Installation-instructions-for-human-beings).
64+
6365
## Installation option 2: one-click installers
6466

65-
[oobabooga-windows.zip](https://github.com/oobabooga/text-generation-webui/releases/download/installers/oobabooga-windows.zip)
67+
[oobabooga-windows.zip](https://github.com/oobabooga/one-click-installers/archive/refs/heads/oobabooga-windows.zip)
6668

67-
[oobabooga-linux.zip](https://github.com/oobabooga/text-generation-webui/releases/download/installers/oobabooga-linux.zip)
69+
[oobabooga-linux.zip](https://github.com/oobabooga/one-click-installers/archive/refs/heads/oobabooga-linux.zip)
6870

6971
Just download the zip above, extract it, and double click on "install". The web UI and all its dependencies will be installed in the same folder.
7072

@@ -139,7 +141,7 @@ Optionally, you can use the following command-line flags:
139141
| `--cpu` | Use the CPU to generate text.|
140142
| `--load-in-8bit` | Load the model with 8-bit precision.|
141143
| `--load-in-4bit` | Load the model with 4-bit precision. Currently only works with LLaMA.|
142-
| `--gptq-bits` | Load a pre-quantized model with specified precision. 2, 3, 4 and 8bit are supported. Currently only works with LLaMA. |
144+
| `--gptq-bits GPTQ_BITS` | Load a pre-quantized model with specified precision. 2, 3, 4 and 8 (bit) are supported. Currently only works with LLaMA. |
143145
| `--bf16` | Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU. |
144146
| `--auto-devices` | Automatically split the model across the available GPU(s) and CPU.|
145147
| `--disk` | If the model is too large for your GPU(s) and CPU combined, send the remaining layers to the disk. |
@@ -155,12 +157,13 @@ Optionally, you can use the following command-line flags:
155157
| `--local_rank LOCAL_RANK` | DeepSpeed: Optional argument for distributed setups. |
156158
| `--rwkv-strategy RWKV_STRATEGY` | RWKV: The strategy to use while loading the model. Examples: "cpu fp32", "cuda fp16", "cuda fp16i8". |
157159
| `--rwkv-cuda-on` | RWKV: Compile the CUDA kernel for better performance. |
158-
| `--no-stream` | Don't stream the text output in real time. This improves the text generation performance.|
160+
| `--no-stream` | Don't stream the text output in real time. |
159161
| `--settings SETTINGS_FILE` | Load the default interface settings from this json file. See `settings-template.json` for an example. If you create a file called `settings.json`, this file will be loaded by default without the need to use the `--settings` flag.|
160162
| `--extensions EXTENSIONS [EXTENSIONS ...]` | The list of extensions to load. If you want to load more than one extension, write the names separated by spaces. |
161163
| `--listen` | Make the web UI reachable from your local network.|
162164
| `--listen-port LISTEN_PORT` | The listening port that the server will use. |
163165
| `--share` | Create a public URL. This is useful for running the web UI on Google Colab or similar. |
166+
| `--auto-launch` | Open the web UI in the default browser upon launch. |
164167
| `--verbose` | Print the prompts to the terminal. |
165168

166169
Out of memory errors? [Check this guide](https://github.com/oobabooga/text-generation-webui/wiki/Low-VRAM-guide).
@@ -179,14 +182,10 @@ Check the [wiki](https://github.com/oobabooga/text-generation-webui/wiki/System-
179182

180183
Pull requests, suggestions, and issue reports are welcome.
181184

182-
Before reporting a bug, make sure that you have created a conda environment and installed the dependencies exactly as in the *Installation* section above.
183-
184-
These issues are known:
185-
186-
* 8-bit doesn't work properly on Windows or older GPUs.
187-
* DeepSpeed doesn't work properly on Windows.
185+
Before reporting a bug, make sure that you have:
188186

189-
For these two, please try commenting on an existing issue instead of creating a new one.
187+
1. Created a conda environment and installed the dependencies exactly as in the *Installation* section above.
188+
2. [Searched](https://github.com/oobabooga/text-generation-webui/issues) to see if an issue already exists for the issue you encountered.
190189

191190
## Credits
192191

extensions/silero_tts/script.py

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import time
12
from pathlib import Path
23

34
import gradio as gr
45
import torch
56

7+
import modules.chat as chat
8+
import modules.shared as shared
9+
610
torch._C._jit_set_profiling_mode(False)
711

812
params = {
@@ -12,10 +16,28 @@
1216
'model_id': 'v3_en',
1317
'sample_rate': 48000,
1418
'device': 'cpu',
19+
'show_text': False,
20+
'autoplay': True,
21+
'voice_pitch': 'medium',
22+
'voice_speed': 'medium',
1523
}
24+
1625
current_params = params.copy()
1726
voices_by_gender = ['en_99', 'en_45', 'en_18', 'en_117', 'en_49', 'en_51', 'en_68', 'en_0', 'en_26', 'en_56', 'en_74', 'en_5', 'en_38', 'en_53', 'en_21', 'en_37', 'en_107', 'en_10', 'en_82', 'en_16', 'en_41', 'en_12', 'en_67', 'en_61', 'en_14', 'en_11', 'en_39', 'en_52', 'en_24', 'en_97', 'en_28', 'en_72', 'en_94', 'en_36', 'en_4', 'en_43', 'en_88', 'en_25', 'en_65', 'en_6', 'en_44', 'en_75', 'en_91', 'en_60', 'en_109', 'en_85', 'en_101', 'en_108', 'en_50', 'en_96', 'en_64', 'en_92', 'en_76', 'en_33', 'en_116', 'en_48', 'en_98', 'en_86', 'en_62', 'en_54', 'en_95', 'en_55', 'en_111', 'en_3', 'en_83', 'en_8', 'en_47', 'en_59', 'en_1', 'en_2', 'en_7', 'en_9', 'en_13', 'en_15', 'en_17', 'en_19', 'en_20', 'en_22', 'en_23', 'en_27', 'en_29', 'en_30', 'en_31', 'en_32', 'en_34', 'en_35', 'en_40', 'en_42', 'en_46', 'en_57', 'en_58', 'en_63', 'en_66', 'en_69', 'en_70', 'en_71', 'en_73', 'en_77', 'en_78', 'en_79', 'en_80', 'en_81', 'en_84', 'en_87', 'en_89', 'en_90', 'en_93', 'en_100', 'en_102', 'en_103', 'en_104', 'en_105', 'en_106', 'en_110', 'en_112', 'en_113', 'en_114', 'en_115']
18-
wav_idx = 0
27+
voice_pitches = ['x-low', 'low', 'medium', 'high', 'x-high']
28+
voice_speeds = ['x-slow', 'slow', 'medium', 'fast', 'x-fast']
29+
30+
# Used for making text xml compatible, needed for voice pitch and speed control
31+
table = str.maketrans({
32+
"<": "&lt;",
33+
">": "&gt;",
34+
"&": "&amp;",
35+
"'": "&apos;",
36+
'"': "&quot;",
37+
})
38+
39+
def xmlesc(txt):
40+
return txt.translate(table)
1941

2042
def load_model():
2143
model, example_text = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_tts', language=params['language'], speaker=params['model_id'])
@@ -33,20 +55,40 @@ def remove_surrounded_chars(string):
3355
new_string += char
3456
return new_string
3557

58+
def remove_tts_from_history(name1, name2):
59+
for i, entry in enumerate(shared.history['internal']):
60+
shared.history['visible'][i] = [shared.history['visible'][i][0], entry[1]]
61+
return chat.generate_chat_output(shared.history['visible'], name1, name2, shared.character)
62+
63+
def toggle_text_in_history(name1, name2):
64+
for i, entry in enumerate(shared.history['visible']):
65+
visible_reply = entry[1]
66+
if visible_reply.startswith('<audio'):
67+
if params['show_text']:
68+
reply = shared.history['internal'][i][1]
69+
shared.history['visible'][i] = [shared.history['visible'][i][0], f"{visible_reply.split('</audio>')[0]}</audio>\n\n{reply}"]
70+
else:
71+
shared.history['visible'][i] = [shared.history['visible'][i][0], f"{visible_reply.split('</audio>')[0]}</audio>"]
72+
return chat.generate_chat_output(shared.history['visible'], name1, name2, shared.character)
73+
3674
def input_modifier(string):
3775
"""
3876
This function is applied to your text inputs before
3977
they are fed into the model.
4078
"""
4179

80+
# Remove autoplay from the last reply
81+
if (shared.args.chat or shared.args.cai_chat) and len(shared.history['internal']) > 0:
82+
shared.history['visible'][-1] = [shared.history['visible'][-1][0], shared.history['visible'][-1][1].replace('controls autoplay>','controls>')]
83+
4284
return string
4385

4486
def output_modifier(string):
4587
"""
4688
This function is applied to the model outputs.
4789
"""
4890

49-
global wav_idx, model, current_params
91+
global model, current_params
5092

5193
for i in params:
5294
if params[i] != current_params[i]:
@@ -57,20 +99,25 @@ def output_modifier(string):
5799
if params['activate'] == False:
58100
return string
59101

102+
original_string = string
60103
string = remove_surrounded_chars(string)
61104
string = string.replace('"', '')
62105
string = string.replace('“', '')
63106
string = string.replace('\n', ' ')
64107
string = string.strip()
65108

66109
if string == '':
67-
string = 'empty reply, try regenerating'
68-
69-
output_file = Path(f'extensions/silero_tts/outputs/{wav_idx:06d}.wav')
70-
model.save_wav(text=string, speaker=params['speaker'], sample_rate=int(params['sample_rate']), audio_path=str(output_file))
71-
72-
string = f'<audio src="file/{output_file.as_posix()}" controls></audio>'
73-
wav_idx += 1
110+
string = '*Empty reply, try regenerating*'
111+
else:
112+
output_file = Path(f'extensions/silero_tts/outputs/{shared.character}_{int(time.time())}.wav')
113+
prosody = '<prosody rate="{}" pitch="{}">'.format(params['voice_speed'], params['voice_pitch'])
114+
silero_input = f'<speak>{prosody}{xmlesc(string)}</prosody></speak>'
115+
model.save_wav(ssml_text=silero_input, speaker=params['speaker'], sample_rate=int(params['sample_rate']), audio_path=str(output_file))
116+
117+
autoplay = 'autoplay' if params['autoplay'] else ''
118+
string = f'<audio src="file/{output_file.as_posix()}" controls {autoplay}></audio>'
119+
if params['show_text']:
120+
string += f'\n\n{original_string}'
74121

75122
return string
76123

@@ -85,9 +132,36 @@ def bot_prefix_modifier(string):
85132

86133
def ui():
87134
# Gradio elements
88-
activate = gr.Checkbox(value=params['activate'], label='Activate TTS')
89-
voice = gr.Dropdown(value=params['speaker'], choices=voices_by_gender, label='TTS voice')
135+
with gr.Accordion("Silero TTS"):
136+
with gr.Row():
137+
activate = gr.Checkbox(value=params['activate'], label='Activate TTS')
138+
autoplay = gr.Checkbox(value=params['autoplay'], label='Play TTS automatically')
139+
show_text = gr.Checkbox(value=params['show_text'], label='Show message text under audio player')
140+
voice = gr.Dropdown(value=params['speaker'], choices=voices_by_gender, label='TTS voice')
141+
with gr.Row():
142+
v_pitch = gr.Dropdown(value=params['voice_pitch'], choices=voice_pitches, label='Voice pitch')
143+
v_speed = gr.Dropdown(value=params['voice_speed'], choices=voice_speeds, label='Voice speed')
144+
with gr.Row():
145+
convert = gr.Button('Permanently replace audios with the message texts')
146+
convert_cancel = gr.Button('Cancel', visible=False)
147+
convert_confirm = gr.Button('Confirm (cannot be undone)', variant="stop", visible=False)
148+
149+
# Convert history with confirmation
150+
convert_arr = [convert_confirm, convert, convert_cancel]
151+
convert.click(lambda :[gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)], None, convert_arr)
152+
convert_confirm.click(lambda :[gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, convert_arr)
153+
convert_confirm.click(remove_tts_from_history, [shared.gradio['name1'], shared.gradio['name2']], shared.gradio['display'])
154+
convert_confirm.click(lambda : chat.save_history(timestamp=False), [], [], show_progress=False)
155+
convert_cancel.click(lambda :[gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, convert_arr)
156+
157+
# Toggle message text in history
158+
show_text.change(lambda x: params.update({"show_text": x}), show_text, None)
159+
show_text.change(toggle_text_in_history, [shared.gradio['name1'], shared.gradio['name2']], shared.gradio['display'])
160+
show_text.change(lambda : chat.save_history(timestamp=False), [], [], show_progress=False)
90161

91162
# Event functions to update the parameters in the backend
92163
activate.change(lambda x: params.update({"activate": x}), activate, None)
164+
autoplay.change(lambda x: params.update({"autoplay": x}), autoplay, None)
93165
voice.change(lambda x: params.update({"speaker": x}), voice, None)
166+
v_pitch.change(lambda x: params.update({"voice_pitch": x}), v_pitch, None)
167+
v_speed.change(lambda x: params.update({"voice_speed": x}), v_speed, None)

modules/RWKV.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def from_pretrained(self, path, dtype="fp16", device="cuda"):
2525
tokenizer_path = Path(f"{path.parent}/20B_tokenizer.json")
2626

2727
if shared.args.rwkv_strategy is None:
28-
model = RWKV(model=os.path.abspath(path), strategy=f'{device} {dtype}')
28+
model = RWKV(model=str(path), strategy=f'{device} {dtype}')
2929
else:
30-
model = RWKV(model=os.path.abspath(path), strategy=shared.args.rwkv_strategy)
31-
pipeline = PIPELINE(model, os.path.abspath(tokenizer_path))
30+
model = RWKV(model=str(path), strategy=shared.args.rwkv_strategy)
31+
pipeline = PIPELINE(model, str(tokenizer_path))
3232

3333
result = self()
3434
result.pipeline = pipeline
@@ -61,7 +61,7 @@ def __init__(self):
6161
@classmethod
6262
def from_pretrained(self, path):
6363
tokenizer_path = path / "20B_tokenizer.json"
64-
tokenizer = Tokenizer.from_file(os.path.abspath(tokenizer_path))
64+
tokenizer = Tokenizer.from_file(str(tokenizer_path))
6565

6666
result = self()
6767
result.tokenizer = tokenizer

0 commit comments

Comments
 (0)