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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
import spaces
|
4 |
+
|
5 |
+
from modules import shared
|
6 |
+
|
7 |
+
import accelerate # This early import makes Intel GPUs happy
|
8 |
+
|
9 |
+
import modules.one_click_installer_check
|
10 |
+
from modules.block_requests import OpenMonkeyPatch, RequestBlocker
|
11 |
+
from modules.logging_colors import logger
|
12 |
+
|
13 |
+
os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
|
14 |
+
os.environ['BITSANDBYTES_NOWELCOME'] = '1'
|
15 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
16 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='Using the update method is deprecated')
|
17 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='Field "model_name" has conflict')
|
18 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='The value passed into gr.Dropdown()')
|
19 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='Field "model_names" has conflict')
|
20 |
+
|
21 |
+
with RequestBlocker():
|
22 |
+
from modules import gradio_hijack
|
23 |
+
import gradio as gr
|
24 |
+
|
25 |
+
import matplotlib
|
26 |
+
|
27 |
+
matplotlib.use('Agg') # This fixes LaTeX rendering on some systems
|
28 |
+
|
29 |
+
import json
|
30 |
+
import os
|
31 |
+
import signal
|
32 |
+
import sys
|
33 |
+
import time
|
34 |
+
from functools import partial
|
35 |
+
from pathlib import Path
|
36 |
+
from threading import Lock
|
37 |
+
|
38 |
+
import yaml
|
39 |
+
|
40 |
+
import modules.extensions as extensions_module
|
41 |
+
from modules import (
|
42 |
+
chat,
|
43 |
+
training,
|
44 |
+
ui,
|
45 |
+
ui_chat,
|
46 |
+
ui_default,
|
47 |
+
ui_file_saving,
|
48 |
+
ui_model_menu,
|
49 |
+
ui_notebook,
|
50 |
+
ui_parameters,
|
51 |
+
ui_session,
|
52 |
+
utils
|
53 |
+
)
|
54 |
+
from modules.extensions import apply_extensions
|
55 |
+
from modules.LoRA import add_lora_to_model
|
56 |
+
from modules.models import load_model
|
57 |
+
from modules.models_settings import (
|
58 |
+
get_fallback_settings,
|
59 |
+
get_model_metadata,
|
60 |
+
update_model_parameters
|
61 |
+
)
|
62 |
+
from modules.shared import do_cmd_flags_warnings
|
63 |
+
from modules.utils import gradio
|
64 |
+
|
65 |
+
|
66 |
+
def signal_handler(sig, frame):
|
67 |
+
logger.info("Received Ctrl+C. Shutting down Text generation web UI gracefully.")
|
68 |
+
sys.exit(0)
|
69 |
+
|
70 |
+
|
71 |
+
signal.signal(signal.SIGINT, signal_handler)
|
72 |
+
|
73 |
+
def create_interface():
|
74 |
+
|
75 |
+
title = 'Text generation web UI'
|
76 |
+
|
77 |
+
# Password authentication
|
78 |
+
auth = []
|
79 |
+
if shared.args.gradio_auth:
|
80 |
+
auth.extend(x.strip() for x in shared.args.gradio_auth.strip('"').replace('\n', '').split(',') if x.strip())
|
81 |
+
if shared.args.gradio_auth_path:
|
82 |
+
with open(shared.args.gradio_auth_path, 'r', encoding="utf8") as file:
|
83 |
+
auth.extend(x.strip() for line in file for x in line.split(',') if x.strip())
|
84 |
+
auth = [tuple(cred.split(':')) for cred in auth]
|
85 |
+
|
86 |
+
# Import the extensions and execute their setup() functions
|
87 |
+
if shared.args.extensions is not None and len(shared.args.extensions) > 0:
|
88 |
+
extensions_module.load_extensions()
|
89 |
+
|
90 |
+
# Force some events to be triggered on page load
|
91 |
+
shared.persistent_interface_state.update({
|
92 |
+
'loader': shared.args.loader or 'Transformers',
|
93 |
+
'mode': shared.settings['mode'],
|
94 |
+
'character_menu': shared.args.character or shared.settings['character'],
|
95 |
+
'instruction_template_str': shared.settings['instruction_template_str'],
|
96 |
+
'prompt_menu-default': shared.settings['prompt-default'],
|
97 |
+
'prompt_menu-notebook': shared.settings['prompt-notebook'],
|
98 |
+
'filter_by_loader': shared.args.loader or 'All'
|
99 |
+
})
|
100 |
+
|
101 |
+
if Path("cache/pfp_character.png").exists():
|
102 |
+
Path("cache/pfp_character.png").unlink()
|
103 |
+
|
104 |
+
# css/js strings
|
105 |
+
css = ui.css
|
106 |
+
js = ui.js
|
107 |
+
css += apply_extensions('css')
|
108 |
+
js += apply_extensions('js')
|
109 |
+
|
110 |
+
# Interface state elements
|
111 |
+
shared.input_elements = ui.list_interface_input_elements()
|
112 |
+
|
113 |
+
with gr.Blocks(css=css, analytics_enabled=False, title=title, theme=ui.theme) as shared.gradio['interface']:
|
114 |
+
|
115 |
+
# Interface state
|
116 |
+
shared.gradio['interface_state'] = gr.State({k: None for k in shared.input_elements})
|
117 |
+
|
118 |
+
# Audio notification
|
119 |
+
if Path("notification.mp3").exists():
|
120 |
+
shared.gradio['audio_notification'] = gr.Audio(interactive=False, value="notification.mp3", elem_id="audio_notification", visible=False)
|
121 |
+
|
122 |
+
# Floating menus for saving/deleting files
|
123 |
+
ui_file_saving.create_ui()
|
124 |
+
|
125 |
+
# Temporary clipboard for saving files
|
126 |
+
shared.gradio['temporary_text'] = gr.Textbox(visible=False)
|
127 |
+
|
128 |
+
# Text Generation tab
|
129 |
+
ui_chat.create_ui()
|
130 |
+
ui_default.create_ui()
|
131 |
+
ui_notebook.create_ui()
|
132 |
+
|
133 |
+
ui_parameters.create_ui(shared.settings['preset']) # Parameters tab
|
134 |
+
ui_model_menu.create_ui() # Model tab
|
135 |
+
training.create_ui() # Training tab
|
136 |
+
ui_session.create_ui() # Session tab
|
137 |
+
|
138 |
+
# Generation events
|
139 |
+
ui_chat.create_event_handlers()
|
140 |
+
ui_default.create_event_handlers()
|
141 |
+
ui_notebook.create_event_handlers()
|
142 |
+
|
143 |
+
# Other events
|
144 |
+
ui_file_saving.create_event_handlers()
|
145 |
+
ui_parameters.create_event_handlers()
|
146 |
+
ui_model_menu.create_event_handlers()
|
147 |
+
|
148 |
+
# Interface launch events
|
149 |
+
shared.gradio['interface'].load(lambda: None, None, None, js=f"() => {{if ({str(shared.settings['dark_theme']).lower()}) {{ document.getElementsByTagName('body')[0].classList.add('dark'); }} }}")
|
150 |
+
shared.gradio['interface'].load(lambda: None, None, None, js=f"() => {{{js}}}")
|
151 |
+
shared.gradio['interface'].load(lambda x: None, gradio('show_controls'), None, js=f'(x) => {{{ui.show_controls_js}; toggle_controls(x)}}')
|
152 |
+
shared.gradio['interface'].load(partial(ui.apply_interface_values, {}, use_persistent=True), None, gradio(ui.list_interface_input_elements()), show_progress=False)
|
153 |
+
shared.gradio['interface'].load(chat.redraw_html, gradio(ui_chat.reload_arr), gradio('display'))
|
154 |
+
|
155 |
+
extensions_module.create_extensions_tabs() # Extensions tabs
|
156 |
+
extensions_module.create_extensions_block() # Extensions block
|
157 |
+
|
158 |
+
# Launch the interface
|
159 |
+
shared.gradio['interface'].queue()
|
160 |
+
with OpenMonkeyPatch():
|
161 |
+
shared.gradio['interface'].launch(
|
162 |
+
max_threads=64,
|
163 |
+
prevent_thread_lock=True,
|
164 |
+
share=shared.args.share,
|
165 |
+
server_name=None if not shared.args.listen else (shared.args.listen_host or '0.0.0.0'),
|
166 |
+
server_port=shared.args.listen_port,
|
167 |
+
inbrowser=shared.args.auto_launch,
|
168 |
+
auth=auth or None,
|
169 |
+
ssl_verify=False if (shared.args.ssl_keyfile or shared.args.ssl_certfile) else True,
|
170 |
+
ssl_keyfile=shared.args.ssl_keyfile,
|
171 |
+
ssl_certfile=shared.args.ssl_certfile,
|
172 |
+
allowed_paths=["cache", "css", "extensions", "js"]
|
173 |
+
)
|
174 |
+
|
175 |
+
if __name__ == "__main__":
|
176 |
+
|
177 |
+
logger.info("Starting Text generation web UI")
|
178 |
+
do_cmd_flags_warnings()
|
179 |
+
|
180 |
+
# Load custom settings
|
181 |
+
settings_file = None
|
182 |
+
if shared.args.settings is not None and Path(shared.args.settings).exists():
|
183 |
+
settings_file = Path(shared.args.settings)
|
184 |
+
elif Path('settings.yaml').exists():
|
185 |
+
settings_file = Path('settings.yaml')
|
186 |
+
elif Path('settings.json').exists():
|
187 |
+
settings_file = Path('settings.json')
|
188 |
+
|
189 |
+
if settings_file is not None:
|
190 |
+
logger.info(f"Loading settings from \"{settings_file}\"")
|
191 |
+
file_contents = open(settings_file, 'r', encoding='utf-8').read()
|
192 |
+
new_settings = json.loads(file_contents) if settings_file.suffix == "json" else yaml.safe_load(file_contents)
|
193 |
+
shared.settings.update(new_settings)
|
194 |
+
|
195 |
+
# Fallback settings for models
|
196 |
+
shared.model_config['.*'] = get_fallback_settings()
|
197 |
+
shared.model_config.move_to_end('.*', last=False) # Move to the beginning
|
198 |
+
|
199 |
+
# Activate the extensions listed on settings.yaml
|
200 |
+
extensions_module.available_extensions = utils.get_available_extensions()
|
201 |
+
for extension in shared.settings['default_extensions']:
|
202 |
+
shared.args.extensions = shared.args.extensions or []
|
203 |
+
if extension not in shared.args.extensions:
|
204 |
+
shared.args.extensions.append(extension)
|
205 |
+
|
206 |
+
available_models = utils.get_available_models()
|
207 |
+
|
208 |
+
# Model defined through --model
|
209 |
+
if shared.args.model is not None:
|
210 |
+
shared.model_name = shared.args.model
|
211 |
+
|
212 |
+
# Select the model from a command-line menu
|
213 |
+
elif shared.args.model_menu:
|
214 |
+
if len(available_models) == 0:
|
215 |
+
logger.error('No models are available! Please download at least one.')
|
216 |
+
sys.exit(0)
|
217 |
+
else:
|
218 |
+
print('The following models are available:\n')
|
219 |
+
for i, model in enumerate(available_models):
|
220 |
+
print(f'{i+1}. {model}')
|
221 |
+
|
222 |
+
print(f'\nWhich one do you want to load? 1-{len(available_models)}\n')
|
223 |
+
i = int(input()) - 1
|
224 |
+
print()
|
225 |
+
|
226 |
+
shared.model_name = available_models[i]
|
227 |
+
|
228 |
+
# If any model has been selected, load it
|
229 |
+
if shared.model_name != 'None':
|
230 |
+
p = Path(shared.model_name)
|
231 |
+
if p.exists():
|
232 |
+
model_name = p.parts[-1]
|
233 |
+
shared.model_name = model_name
|
234 |
+
else:
|
235 |
+
model_name = shared.model_name
|
236 |
+
|
237 |
+
model_settings = get_model_metadata(model_name)
|
238 |
+
update_model_parameters(model_settings, initial=True) # hijack the command-line arguments
|
239 |
+
|
240 |
+
# Load the model
|
241 |
+
shared.model, shared.tokenizer = load_model(model_name)
|
242 |
+
if shared.args.lora:
|
243 |
+
add_lora_to_model(shared.args.lora)
|
244 |
+
|
245 |
+
shared.generation_lock = Lock()
|
246 |
+
|
247 |
+
if shared.args.nowebui:
|
248 |
+
# Start the API in standalone mode
|
249 |
+
shared.args.extensions = [x for x in shared.args.extensions if x != 'gallery']
|
250 |
+
if shared.args.extensions is not None and len(shared.args.extensions) > 0:
|
251 |
+
extensions_module.load_extensions()
|
252 |
+
else:
|
253 |
+
# Launch the web UI
|
254 |
+
create_interface()
|
255 |
+
while True:
|
256 |
+
time.sleep(0.5)
|
257 |
+
if shared.need_restart:
|
258 |
+
shared.need_restart = False
|
259 |
+
time.sleep(0.5)
|
260 |
+
shared.gradio['interface'].close()
|
261 |
+
time.sleep(0.5)
|
262 |
+
create_interface()
|