mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-10-01 01:26:03 -04:00
Improvements to character_bias extension
This commit is contained in:
parent
248742df1c
commit
91c2b8e11c
@ -18,7 +18,7 @@ with open(bias_file, "r") as f:
|
||||
params = {
|
||||
"activate": True,
|
||||
"bias string": " *I am so happy*",
|
||||
"use custom string": False,
|
||||
"custom string": "",
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ def bot_prefix_modifier(string):
|
||||
behavior.
|
||||
"""
|
||||
if params['activate']:
|
||||
if params['use custom string']:
|
||||
if params['custom string'].strip() != '':
|
||||
return f'{string} {params["custom string"].strip()} '
|
||||
else:
|
||||
return f'{string} {params["bias string"].strip()} '
|
||||
@ -56,8 +56,7 @@ def ui():
|
||||
# Gradio elements
|
||||
activate = gr.Checkbox(value=params['activate'], label='Activate character bias')
|
||||
dropdown_string = gr.Dropdown(choices=bias_options, value=params["bias string"], label='Character bias', info='To edit the options in this dropdown edit the "bias_options.txt" file')
|
||||
use_custom_string = gr.Checkbox(value=False, label='Use custom bias textbox instead of dropdown')
|
||||
custom_string = gr.Textbox(value="", placeholder="Enter custom bias string", label="Custom Character Bias", info='To use this textbox activate the checkbox above')
|
||||
custom_string = gr.Textbox(value=params['custom string'], placeholder="Enter custom bias string", label="Custom Character Bias", info='If not empty, will be used instead of the value above')
|
||||
|
||||
# Event functions to update the parameters in the backend
|
||||
def update_bias_string(x):
|
||||
@ -73,11 +72,3 @@ def ui():
|
||||
dropdown_string.change(update_bias_string, dropdown_string, None)
|
||||
custom_string.change(update_custom_string, custom_string, None)
|
||||
activate.change(lambda x: params.update({"activate": x}), activate, None)
|
||||
use_custom_string.change(lambda x: params.update({"use custom string": x}), use_custom_string, None)
|
||||
|
||||
# Group elements together depending on the selected option
|
||||
def bias_string_group():
|
||||
if use_custom_string.value:
|
||||
return gr.Group([use_custom_string, custom_string])
|
||||
else:
|
||||
return dropdown_string
|
||||
|
Loading…
Reference in New Issue
Block a user