Skip to content

Commit

Permalink
bugfix npz loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rsxdalv committed Sep 2, 2024
1 parent e157483 commit 65189f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ node_modules/
# Ignore temporary Jupiter notebooks
*.temp.ipynb

# Temporary file used by some modules
# Temporary files used by some modules
output.wav
log.out
2 changes: 2 additions & 0 deletions tts_webui/bark/npz_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def save_npz_musicgen(filename: str, tokens: torch.Tensor, metadata: dict[str, A
def load_npz(filename):
def unpack_metadata(metadata: np.ndarray):
def join_list(x: list | np.ndarray):
if isinstance(x, np.ndarray):
x = x.tolist()
return "".join(x)

return json.loads(join_list(metadata))
Expand Down
17 changes: 13 additions & 4 deletions tts_webui/history_tab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
)
from tts_webui.history_tab.get_wav_files import get_wav_files
from tts_webui.history_tab.delete_generation_cb import delete_generation_cb
from tts_webui.history_tab.save_to_favorites import save_to_collection, save_to_favorites
from tts_webui.history_tab.save_to_favorites import (
save_to_collection,
save_to_favorites,
)
from tts_webui.history_tab.open_folder import open_folder


Expand All @@ -23,12 +26,18 @@ def _get_filename(table, index):
return table["data"][index][-1]


def get_json_text(filename):
try:
with open(filename) as f:
return json.load(f)
except:
return None


def _select_audio(table, evt: gr.SelectData):
index = _get_row_index(evt)
filename = _get_filename(table, index)
with open(filename.replace(".wav", ".json")) as f:
json_text = json.load(f)
return filename, json_text
return filename, get_json_text(filename.replace(".wav", ".json"))


def clear_audio():
Expand Down

0 comments on commit 65189f9

Please sign in to comment.