mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 16:17:57 +01:00
Add ui() function to extensions
This commit is contained in:
parent
2b4ce79b6f
commit
e51ece21c0
@ -1,3 +1,5 @@
|
|||||||
|
import gradio as gr
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"bias string": " *I speak in an annoyingly cute way*",
|
"bias string": " *I speak in an annoyingly cute way*",
|
||||||
}
|
}
|
||||||
@ -25,3 +27,10 @@ def bot_prefix_modifier(string):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return f'{string} {params["bias string"].strip()} '
|
return f'{string} {params["bias string"].strip()} '
|
||||||
|
|
||||||
|
def ui():
|
||||||
|
# Gradio elements
|
||||||
|
string = gr.Textbox(value=params["bias string"], label='Character bias')
|
||||||
|
|
||||||
|
# Event functions to update the parameters in the backend
|
||||||
|
string.change(lambda x: params.update({"bias string": x}), string, None)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
|
import gradio as gr
|
||||||
from deep_translator import GoogleTranslator
|
from deep_translator import GoogleTranslator
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"language string": "ja",
|
"language string": "ja",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
language_codes = {'Afrikaans': 'af', 'Albanian': 'sq', 'Amharic': 'am', 'Arabic': 'ar', 'Armenian': 'hy', 'Azerbaijani': 'az', 'Basque': 'eu', 'Belarusian': 'be', 'Bengali': 'bn', 'Bosnian': 'bs', 'Bulgarian': 'bg', 'Catalan': 'ca', 'Cebuano': 'ceb', 'Chinese (Simplified)': 'zh-CN', 'Chinese (Traditional)': 'zh-TW', 'Corsican': 'co', 'Croatian': 'hr', 'Czech': 'cs', 'Danish': 'da', 'Dutch': 'nl', 'English': 'en', 'Esperanto': 'eo', 'Estonian': 'et', 'Finnish': 'fi', 'French': 'fr', 'Frisian': 'fy', 'Galician': 'gl', 'Georgian': 'ka', 'German': 'de', 'Greek': 'el', 'Gujarati': 'gu', 'Haitian Creole': 'ht', 'Hausa': 'ha', 'Hawaiian': 'haw', 'Hebrew': 'iw', 'Hindi': 'hi', 'Hmong': 'hmn', 'Hungarian': 'hu', 'Icelandic': 'is', 'Igbo': 'ig', 'Indonesian': 'id', 'Irish': 'ga', 'Italian': 'it', 'Japanese': 'ja', 'Javanese': 'jw', 'Kannada': 'kn', 'Kazakh': 'kk', 'Khmer': 'km', 'Korean': 'ko', 'Kurdish': 'ku', 'Kyrgyz': 'ky', 'Lao': 'lo', 'Latin': 'la', 'Latvian': 'lv', 'Lithuanian': 'lt', 'Luxembourgish': 'lb', 'Macedonian': 'mk', 'Malagasy': 'mg', 'Malay': 'ms', 'Malayalam': 'ml', 'Maltese': 'mt', 'Maori': 'mi', 'Marathi': 'mr', 'Mongolian': 'mn', 'Myanmar (Burmese)': 'my', 'Nepali': 'ne', 'Norwegian': 'no', 'Nyanja (Chichewa)': 'ny', 'Pashto': 'ps', 'Persian': 'fa', 'Polish': 'pl', 'Portuguese (Portugal, Brazil)': 'pt', 'Punjabi': 'pa', 'Romanian': 'ro', 'Russian': 'ru', 'Samoan': 'sm', 'Scots Gaelic': 'gd', 'Serbian': 'sr', 'Sesotho': 'st', 'Shona': 'sn', 'Sindhi': 'sd', 'Sinhala (Sinhalese)': 'si', 'Slovak': 'sk', 'Slovenian': 'sl', 'Somali': 'so', 'Spanish': 'es', 'Sundanese': 'su', 'Swahili': 'sw', 'Swedish': 'sv', 'Tagalog (Filipino)': 'tl', 'Tajik': 'tg', 'Tamil': 'ta', 'Telugu': 'te', 'Thai': 'th', 'Turkish': 'tr', 'Ukrainian': 'uk', 'Urdu': 'ur', 'Uzbek': 'uz', 'Vietnamese': 'vi', 'Welsh': 'cy', 'Xhosa': 'xh', 'Yiddish': 'yi', 'Yoruba': 'yo', 'Zulu': 'zu'}
|
||||||
|
|
||||||
def input_modifier(string):
|
def input_modifier(string):
|
||||||
"""
|
"""
|
||||||
This function is applied to your text inputs before
|
This function is applied to your text inputs before
|
||||||
@ -27,3 +30,13 @@ def bot_prefix_modifier(string):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def ui():
|
||||||
|
# Finding the language name from the language code to use as the default value
|
||||||
|
language_name = list(language_codes.keys())[list(language_codes.values()).index(params['language string'])]
|
||||||
|
|
||||||
|
# Gradio elements
|
||||||
|
language = gr.Dropdown(value=language_name, choices=[k for k in language_codes], label='Language')
|
||||||
|
|
||||||
|
# Event functions to update the parameters in the backend
|
||||||
|
language.change(lambda x: params.update({"language string": language_codes[x]}), language, None)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import gradio as gr
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
torch._C._jit_set_profiling_mode(False)
|
torch._C._jit_set_profiling_mode(False)
|
||||||
@ -81,3 +82,12 @@ def bot_prefix_modifier(string):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def ui():
|
||||||
|
# Gradio elements
|
||||||
|
activate = gr.Checkbox(value=params['activate'], label='Activate TTS')
|
||||||
|
voice = gr.Dropdown(value=params['speaker'], choices=[f'en_{i}' for i in range(1, 118)], label='TTS voice')
|
||||||
|
|
||||||
|
# Event functions to update the parameters in the backend
|
||||||
|
activate.change(lambda x: params.update({"activate": x}), activate, None)
|
||||||
|
voice.change(lambda x: params.update({"speaker": x}), voice, None)
|
||||||
|
@ -32,31 +32,15 @@ def apply_extensions(text, typ):
|
|||||||
text = extension.bot_prefix_modifier(text)
|
text = extension.bot_prefix_modifier(text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def update_extensions_parameters(*args):
|
|
||||||
i = 0
|
|
||||||
for extension, _ in iterator():
|
|
||||||
for param in extension.params:
|
|
||||||
if len(args) >= i+1:
|
|
||||||
extension.params[param] = eval(f"args[{i}]")
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
def create_extensions_block():
|
def create_extensions_block():
|
||||||
extensions_ui_elements = []
|
# Updating the default values
|
||||||
default_values = []
|
|
||||||
if not (shared.args.chat or shared.args.cai_chat):
|
|
||||||
gr.Markdown('## Extensions parameters')
|
|
||||||
for extension, name in iterator():
|
for extension, name in iterator():
|
||||||
for param in extension.params:
|
for param in extension.params:
|
||||||
_id = f"{name}-{param}"
|
_id = f"{name}-{param}"
|
||||||
default_value = shared.settings[_id] if _id in shared.settings else extension.params[param]
|
if _id in shared.settings:
|
||||||
default_values.append(default_value)
|
extension.params[param] = shared.settings[_id]
|
||||||
if type(extension.params[param]) == str:
|
|
||||||
extensions_ui_elements.append(gr.Textbox(value=default_value, label=f"{name}-{param}"))
|
|
||||||
elif type(extension.params[param]) in [int, float]:
|
|
||||||
extensions_ui_elements.append(gr.Number(value=default_value, label=f"{name}-{param}"))
|
|
||||||
elif type(extension.params[param]) == bool:
|
|
||||||
extensions_ui_elements.append(gr.Checkbox(value=default_value, label=f"{name}-{param}"))
|
|
||||||
|
|
||||||
update_extensions_parameters(*default_values)
|
# Creating the extension ui elements
|
||||||
btn_extensions = gr.Button("Apply")
|
for extension, name in iterator():
|
||||||
btn_extensions.click(update_extensions_parameters, [*extensions_ui_elements], [])
|
if hasattr(extension, "ui"):
|
||||||
|
extension.ui()
|
||||||
|
@ -351,7 +351,6 @@ else:
|
|||||||
shared.gradio['Stop'].click(None, None, None, cancels=gen_events)
|
shared.gradio['Stop'].click(None, None, None, cancels=gen_events)
|
||||||
|
|
||||||
shared.gradio['interface'].queue()
|
shared.gradio['interface'].queue()
|
||||||
print([key for key in shared.gradio])
|
|
||||||
if shared.args.listen:
|
if shared.args.listen:
|
||||||
shared.gradio['interface'].launch(prevent_thread_lock=True, share=shared.args.share, server_name='0.0.0.0', server_port=shared.args.listen_port)
|
shared.gradio['interface'].launch(prevent_thread_lock=True, share=shared.args.share, server_name='0.0.0.0', server_port=shared.args.listen_port)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user