Skip to content

Commit

Permalink
Fixing errors and upgrading gradio
Browse files Browse the repository at this point in the history
* suppress gradio and triton warnings

* upgrade gradio and fix visual issues
  • Loading branch information
rsxdalv authored Jan 15, 2024
1 parent 06ab788 commit 8b0f102
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 74 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ https://rsxdalv.github.io/bark-speaker-directory/
## Info about managing models, caches and system space for AI projects
https://github.com/rsxdalv/tts-generation-webui/discussions/186#discussioncomment-7291274

## Changelog
## Changelo
Jan 15:
* Upgraded Gradio to 3.48.0
* Several visual bugs have appeared, if they are critical, please report them or downgrade gradio.
* Gradio: Suppress useless warnings
* Supress Triton warnings
* Gradio-Bark: Fix "Use last generation as history" behavior, empty selection no longer errors
* Improve extensions loader display

Jan 14:
* React UI: Fix missing directory errors

Expand All @@ -50,7 +58,7 @@ Jan 13:
Jan 12:
* React UI: Fix names for audio actions
* Gradio: Fix multiple API warnings
* Integration - React UI now is launched alongside Gradio, with a link to open it.
* Integration - React UI now is launched alongside Gradio, with a link to open it

Jan 11:
* React UI: Make the build work without any errors
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
safetensors==0.3.1 # Until they fix it
torch==2.0.0 # BSD 3-Clause - ensures torch is not reinstalled
ffmpeg-python # Apache 2.0
gradio==3.35.2
gradio==3.48.0
python-dotenv==1.0.0
soundfile==0.12.1; sys_platform == 'win32' # torchaudio
# sox # torchaudio for linux
Expand Down
32 changes: 26 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
import src.utils.setup_or_recover as setup_or_recover
import src.utils.dotenv_init as dotenv_init
import gradio as gr
import warnings

warnings.filterwarnings(
"ignore",
message="Using the update method is deprecated. Simply return a new object instead",
)
warnings.filterwarnings(
"ignore",
message="Trying to convert audio automatically from float32 to 16-bit int format.",
)

import logging

# suppress warning from logging "A matching Triton is not available, some optimizations will not be enabled"
# suppress warning from logging "Triton is not available, some optimizations will not be enabled."
logging.getLogger("xformers").addFilter(
lambda record: "Triton is not available" not in record.getMessage()
)

from src.config.load_config import default_config
from src.config.config import config
Expand All @@ -10,6 +28,7 @@
from src.Joutai import Joutai
from src.history_tab.collections_directories_atom import collections_directories_atom


setup_or_recover.dummy()
dotenv_init.init()

Expand All @@ -35,7 +54,9 @@ def reload_config_and_restart_ui():
title="TTS Generation WebUI",
analytics_enabled=False, # it broke too many times
) as demo:
gr.Markdown("# TTS Generation WebUI (Bark, MusicGen + AudioGen, Tortoise, RVC) [NEW React UI (Beta)](http://localhost:3000)")
gr.Markdown(
"# TTS Generation WebUI (Bark, MusicGen + AudioGen, Tortoise, RVC) [NEW React UI (Beta)](http://localhost:3000)"
)
with Joutai.singleton.tabs:
from src.tortoise.generation_tab_tortoise import generation_tab_tortoise
from src.settings_tab_gradio import settings_tab_gradio
Expand Down Expand Up @@ -122,7 +143,7 @@ def reload_config_and_restart_ui():


def print_pretty_options(options):
print("Gradio interface options:")
print(" Gradio interface options:")
max_key_length = max(len(key) for key in options.keys())
for key, value in options.items():
if key == "auth" and value is not None:
Expand All @@ -138,9 +159,8 @@ def print_pretty_options(options):


print("Starting Gradio server...")
if not gradio_interface_options["enable_queue"]:
print("Warning: Gradio server queue is disabled. Automatically enabling")
gradio_interface_options["enable_queue"] = True
if "enable_queue" in gradio_interface_options:
del gradio_interface_options["enable_queue"]
if gradio_interface_options["auth"] is not None:
# split username:password into (username, password)
gradio_interface_options["auth"] = tuple(
Expand All @@ -156,8 +176,8 @@ def start_server():
).launch(**gradio_interface_options)



if __name__ == "__main__":
import subprocess

subprocess.Popen("npm start --prefix react-ui", shell=True)
start_server()
4 changes: 4 additions & 0 deletions src/bark/bark_css.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
height: 150px;
min-height: 150px;
}
.tts-image > button {
width: 100%;
height: 100%;
}
"""
119 changes: 55 additions & 64 deletions src/bark/generation_tab_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,13 @@ def gen(
if prompt is None or prompt == "":
raise ValueError("Prompt is empty")

print(
"gen",
"old_generation_filename",
old_generation_filename,
"semantic",
history_prompt_semantic,
)
if history_prompt_semantic == "":
history_prompt_semantic = None
if history_prompt_semantic is not None:
history_prompt_semantic = load_npz(history_prompt_semantic)

if history_setting == HistorySettings.NPZ_FILE:
if old_generation_filename is None:
raise ValueError("old_generation_filename is None")
history_prompt = load_npz(old_generation_filename)
history_prompt_semantic = (
load_npz(history_prompt_semantic) if history_prompt_semantic else None
)
history_prompt = (
load_npz(old_generation_filename) if old_generation_filename else None
)

_original_history_prompt = history_prompt

Expand Down Expand Up @@ -481,8 +472,8 @@ def generation_tab_bark():
with gr.Tab(label="Generation (Bark)", id="generation_bark"):
with gr.Row():
history_setting = gr.Radio(
HistorySettings.choices,
value="Empty history",
HistorySettings.choices, # type: ignore
value=HistorySettings.EMPTY,
type="value",
label="History Prompt (voice) setting:",
)
Expand Down Expand Up @@ -519,19 +510,17 @@ def unload_models():
outputs=[column], # type: ignore
)

with gr.Row():
(
history_prompt_semantic_dropdown,
copy_history_prompt_semantic_button,
reload_history_prompt_semantic_dropdown,
) = old_generation_dropdown_ui("Semantic Voice (Optional)")
(
history_prompt_semantic_dropdown,
copy_history_prompt_semantic_button,
reload_history_prompt_semantic_dropdown,
) = old_generation_dropdown_ui("Semantic Voice (Optional)")

with gr.Row():
(
old_generation_dropdown,
copy_old_generation_button,
reload_old_generation_dropdown,
) = old_generation_dropdown_ui("Audio Voice")
(
old_generation_dropdown,
copy_old_generation_button,
reload_old_generation_dropdown,
) = old_generation_dropdown_ui("Audio Voice")

history_setting.change(
fn=lambda choice: [
Expand Down Expand Up @@ -564,14 +553,14 @@ def unload_models():
with gr.Row():
with gr.Column():
long_prompt_radio = gr.Radio(
PromptSplitSettings.choices,
PromptSplitSettings.choices, # type: ignore
type="value",
label="Prompt type",
value=PromptSplitSettings.NONE,
show_label=False,
)
long_prompt_history_radio = gr.Radio(
LongPromptHistorySettings.choices,
LongPromptHistorySettings.choices, # type: ignore
type="value",
label="For each subsequent generation:",
value=LongPromptHistorySettings.CONTINUE,
Expand Down Expand Up @@ -741,40 +730,42 @@ def register_use_as_history_button(button, source):


def old_generation_dropdown_ui(label):
old_generation_dropdown = gr.Dropdown(
label=label,
choices=get_npz_files(),
type="value",
value=None,
allow_custom_value=True,
visible=False,
container=False,
)
copy_old_generation_button = gr.Button(
"save",
visible=False,
elem_classes="btn-sm material-symbols-outlined",
size="sm",
)
copy_old_generation_button.click(
fn=lambda x: [
shutil.copy(x, os.path.join("voices", os.path.basename(x))),
],
inputs=[old_generation_dropdown],
)
with gr.Row():
old_generation_dropdown = gr.Dropdown(
label=label,
choices=get_npz_files(), # type: ignore
type="value",
value=None,
allow_custom_value=True,
visible=False,
# container=False,
show_label=True,
)
copy_old_generation_button = gr.Button(
"save",
visible=False,
elem_classes="btn-sm material-symbols-outlined",
size="sm",
)
copy_old_generation_button.click(
fn=lambda x: [
shutil.copy(x, os.path.join("voices", os.path.basename(x))),
],
inputs=[old_generation_dropdown],
)

reload_old_generation_dropdown = gr.Button(
"refresh",
visible=False,
elem_classes=ICON_ELEM_CLASS,
size="sm",
)
reload_old_generation_dropdown = gr.Button(
"refresh",
visible=False,
elem_classes=ICON_ELEM_CLASS,
size="sm",
)

reload_old_generation_dropdown.click(
fn=lambda: gr.Dropdown.update(choices=get_npz_files()),
outputs=old_generation_dropdown,
api_name=f"reload_old_generation_dropdown{ '' if label == 'Audio Voice' else '_semantic'}",
)
reload_old_generation_dropdown.click(
fn=lambda: gr.Dropdown.update(choices=get_npz_files()), # type: ignore
outputs=old_generation_dropdown,
api_name=f"reload_old_generation_dropdown{ '' if label == 'Audio Voice' else '_semantic'}",
)

return (
old_generation_dropdown,
Expand All @@ -798,7 +789,7 @@ def setup_bark_voice_prompt_ui():

speaker_ids = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
speakerIdRadio = gr.Radio(
speaker_ids, type="value", label="Speaker ID", value="0"
speaker_ids, type="value", label="Speaker ID", value="0" # type: ignore
)

voice_inputs = [useV2, languageRadio, speakerIdRadio]
Expand Down
4 changes: 3 additions & 1 deletion src/extensions_loader/ext_callback_save_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
for file_name in extension_files:
if file_name.endswith(".py"):
module_name = file_name[:-3]
print(" ", end="")
try:
spec = importlib.util.spec_from_file_location(
module_name, os.path.join(extensions_folder, file_name)
Expand Down Expand Up @@ -48,8 +49,9 @@
f"Module {module_name} does not contain the function 'callback_save_generation'"
)

# print(f"Loaded {len(callbacks_save_generation)} extensions.")
print(" ", end="")
print(f"Loaded {len(callbacks_save_generation)} callback_save_generation extensions.")
print(" ", end="")
print(
f"Loaded {len(callbacks_save_generation_musicgen)} callback_save_generation_musicgen extensions."
)
Expand Down
1 change: 1 addition & 0 deletions src/history_tab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def history_content(
max_cols=len(datatypes),
datatype=datatypes,
headers=headers,
height=800,
)

with gr.Column():
Expand Down
1 change: 1 addition & 0 deletions src/history_tab/voices_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def voices_tab(register_use_as_history_button, directory="voices"):
col_count=len(datatypes),
max_cols=len(datatypes),
headers=headers,
height=800,
# elem_classes="file-list"
)
with gr.Column():
Expand Down

0 comments on commit 8b0f102

Please sign in to comment.