Skip to content

Commit

Permalink
Tortoise new params (#54)
Browse files Browse the repository at this point in the history
* define Tortoise Parameters as a class

* define tortoise as a dependency in requirements

* add ffmpeg checks and avoid failing on extensions

* clean up

* migrate to new gradio

* show error when Bark Voice Clone fails

* add new params to tortoise
  • Loading branch information
rsxdalv authored Jun 29, 2023
1 parent ad3a33e commit 605724f
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 142 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# pip install nodejs-bin==16.15.1a4
ffmpeg-python # Apache 2.0
gradio==3.33.1
gradio==3.35.2
python-dotenv==1.0.0
soundfile==0.12.1 # torchaudio platform windows
# run_cmd("pip install sox") # torchaudio platform linux
# audiocraft==0.0.1 # MIT License
audiocraft @ git+https://[email protected]/facebookresearch/audiocraft#egg=audiocraft@c9179f8 # MIT License
vocos==0.0.2 # MIT License
tortoise @ git+https://github.com/rsxdalv/tortoise-tts#egg=tortoise@f04f95e30245c85996be3af068cba4890952b1a1 # Apache 2.0
3 changes: 3 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def reload_config_and_restart_ui():

tab_voice_clone(register_use_as_history_button)
except Exception as e:
with gr.Tab("Bark Voice Clone (!)"):
gr.Markdown("Failed to load voice clone demo")
gr.Markdown(f"Error: {e}")
print("Failed to load voice clone demo")
print(e)

Expand Down
10 changes: 6 additions & 4 deletions src/bark/generation_tab_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,14 @@ def generation_tab_bark(tabs):
value=None,
allow_custom_value=True,
visible=False,
container=False,
)
old_generation_dropdown.style(container=False)
copy_old_generation_button = gr.Button(
"save", visible=False, elem_classes="btn-sm material-symbols-outlined"
"save",
visible=False,
elem_classes="btn-sm material-symbols-outlined",
size="sm",
)
copy_old_generation_button.style(size="sm")
copy_old_generation_button.click(
fn=lambda x: [
shutil.copy(x, os.path.join("voices", os.path.basename(x))),
Expand All @@ -522,8 +524,8 @@ def generation_tab_bark(tabs):
"refresh",
visible=False,
elem_classes="btn-sm material-symbols-outlined",
size="sm",
)
reload_old_generation_dropdown.style(size="sm")

reload_old_generation_dropdown.click(
fn=lambda: gr.Dropdown.update(choices=get_npz_files()),
Expand Down
9 changes: 3 additions & 6 deletions src/bark/setup_seed_ui_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
def setup_seed_ui_bark():
gr.Markdown("Seed")
with gr.Row():
seed_input = gr.Textbox(value="-1", show_label=False)
seed_input.style(container=False)
seed_input = gr.Textbox(value="-1", show_label=False, container=False)
set_random_seed_button = gr.Button(
"backspace", elem_classes="btn-sm material-symbols-outlined"
"backspace", elem_classes="btn-sm material-symbols-outlined", size="sm"
)

set_random_seed_button.style(size="sm")
set_random_seed_button.click(
fn=lambda: gr.Textbox.update(value="-1"), outputs=[seed_input]
)

set_old_seed_button = gr.Button(
"repeat", elem_classes="btn-sm material-symbols-outlined"
"repeat", elem_classes="btn-sm material-symbols-outlined", size="sm"
)

set_old_seed_button.style(size="sm")
return seed_input, set_old_seed_button
30 changes: 18 additions & 12 deletions src/extensions_loader/ext_callback_save_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ def ext_callback_save_generation(
metadata: Dict[str, Any],
) -> None:
for callback in callbacks_save_generation:
callback(
full_generation=full_generation,
audio_array=audio_array,
files=files,
metadata=metadata,
)
try:
callback(
full_generation=full_generation,
audio_array=audio_array,
files=files,
metadata=metadata,
)
except Exception as e:
print("Error in callback_save_generation extension:", e)


def ext_callback_save_generation_musicgen(
Expand All @@ -78,12 +81,15 @@ def ext_callback_save_generation_musicgen(
SAMPLE_RATE: int,
) -> None:
for callback in callbacks_save_generation_musicgen:
callback(
audio_array=audio_array,
files=files,
metadata=metadata,
SAMPLE_RATE=SAMPLE_RATE,
)
try:
callback(
audio_array=audio_array,
files=files,
metadata=metadata,
SAMPLE_RATE=SAMPLE_RATE,
)
except Exception as e:
print("Error in callback_save_generation_musicgen extension:", e)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import base64


def check_ffmpeg():
if not hasattr(ffmpeg, "input"):
raise ImportError(
"""Incorrect ffmpeg version. Please install ffmpeg-python with `pip install ffmpeg-python`"""
)


def ndarray_to_base64(arr):
# Convert ndarray to bytes
arr_bytes = arr.tobytes()
Expand All @@ -31,6 +38,7 @@ def callback_save_generation(
files: Dict[str, str],
metadata: Dict[str, Any],
) -> None:
check_ffmpeg()
print("Saving generation to", files.get("ogg"))

attach_generation_meta(full_generation, "semantic_prompt", metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
import ffmpeg


def check_ffmpeg():
if not hasattr(ffmpeg, "input"):
raise ImportError(
"""Incorrect ffmpeg version. Please install ffmpeg-python with `pip install ffmpeg-python`"""
)


def callback_save_generation_musicgen(
audio_array: np.ndarray,
files: Dict[str, str],
metadata: Dict[str, Any],
SAMPLE_RATE: int,
) -> None:
check_ffmpeg()
print("Saving generation to", files.get("ogg"))

filename = files.get("ogg")
Expand Down
3 changes: 1 addition & 2 deletions src/history_tab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def history_content(
create_collection_ui(collections_directories_atom)

with gr.Accordion("Gallery Selector (Click to Open)", open=False):
history_list_as_gallery = gr.Gallery(value=[])
history_list_as_gallery.style(columns=8, object_fit="contain", height="auto")
history_list_as_gallery = gr.Gallery(value=[], columns=8, object_fit="contain", height="auto")
with gr.Row():
with gr.Column():
with gr.Row():
Expand Down
10 changes: 3 additions & 7 deletions src/musicgen/setup_seed_ui_musicgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
def setup_seed_ui_musicgen():
gr.Markdown("Seed")
with gr.Row():
seed_input = gr.Number(value=-1, show_label=False)
seed_input.style(container=False)
seed_input = gr.Number(value=-1, show_label=False, container=False)
set_random_seed_button = gr.Button(
"backspace", elem_classes="btn-sm material-symbols-outlined"
"backspace", elem_classes="btn-sm material-symbols-outlined", size="sm"
)

set_random_seed_button.style(size="sm")
set_random_seed_button.click(
fn=lambda: gr.Number.update(value=-1), outputs=[seed_input]
)

set_old_seed_button = gr.Button(
"repeat", elem_classes="btn-sm material-symbols-outlined"
"repeat", elem_classes="btn-sm material-symbols-outlined", size="sm"
)

set_old_seed_button.style(size="sm")

def link_seed_cache(seed_cache):
set_old_seed_button.click(
fn=lambda x: gr.Number.update(value=x),
Expand Down
Loading

0 comments on commit 605724f

Please sign in to comment.