Move all gradio elements to shared (so that extensions can use them)

This commit is contained in:
oobabooga 2023-02-24 16:46:50 -03:00
parent 0a3590da8c
commit 65326b545a
6 changed files with 127 additions and 124 deletions

View file

@ -253,7 +253,7 @@ def tokenize_dialogue(dialogue, name1, name2):
_history.append(entry)
entry = ['', '']
print(f"\033[1;32;1m\nDialogue tokenized to:\033[0;37;0m\n", end='')
print("\033[1;32;1m\nDialogue tokenized to:\033[0;37;0m\n", end='')
for row in _history:
for column in row:
print("\n")
@ -301,8 +301,8 @@ def load_history(file, name1, name2):
shared.history['visible'] = copy.deepcopy(shared.history['internal'])
def load_default_history(name1, name2):
if Path(f'logs/persistent.json').exists():
load_history(open(Path(f'logs/persistent.json'), 'rb').read(), name1, name2)
if Path('logs/persistent.json').exists():
load_history(open(Path('logs/persistent.json'), 'rb').read(), name1, name2)
else:
shared.history['internal'] = []
shared.history['visible'] = []
@ -370,5 +370,5 @@ def upload_tavern_character(img, name1, name2):
def upload_your_profile_picture(img):
img = Image.open(io.BytesIO(img))
img.save(Path(f'img_me.png'))
print(f'Profile picture saved to "img_me.png"')
img.save(Path('img_me.png'))
print('Profile picture saved to "img_me.png"')

View file

@ -13,7 +13,7 @@ def load_extensions():
print(f'Loading the extension "{name}"... ', end='')
exec(f"import extensions.{name}.script")
state[name] = [True, i]
print(f'Ok.')
print('Ok.')
# This iterator returns the extensions in the order specified in the command-line
def iterator():

View file

@ -117,7 +117,7 @@ def load_model(model_name):
model = eval(command)
# Loading the tokenizer
if shared.model_name.lower().startswith(('gpt4chan', 'gpt-4chan', '4chan')) and Path(f"models/gpt-j-6B/").exists():
if shared.model_name.lower().startswith(('gpt4chan', 'gpt-4chan', '4chan')) and Path("models/gpt-j-6B/").exists():
tokenizer = AutoTokenizer.from_pretrained(Path("models/gpt-j-6B/"))
else:
tokenizer = AutoTokenizer.from_pretrained(Path(f"models/{shared.model_name}/"))

View file

@ -11,6 +11,9 @@ history = {'internal': [], 'visible': []}
character = 'None'
stop_everything = False
# UI elements (buttons, sliders, HTML, etc)
gradio = {}
settings = {
'max_new_tokens': 200,
'max_new_tokens_min': 1,

View file

@ -126,9 +126,9 @@ def generate_reply(question, tokens, do_sample, max_new_tokens, temperature, top
if shared.args.deepspeed:
generate_params.append("synced_gpus=True")
if shared.args.no_stream:
generate_params.append(f"max_new_tokens=tokens")
generate_params.append("max_new_tokens=tokens")
else:
generate_params.append(f"max_new_tokens=8")
generate_params.append("max_new_tokens=8")
if shared.soft_prompt:
inputs_embeds, filler_input_ids = generate_softprompt_input_tensors(input_ids)