Skip to content

Commit

Permalink
fix. force reload from custom cache file to override infer_gradio ini…
Browse files Browse the repository at this point in the history
…t loaded value in case webpage refreshed
  • Loading branch information
SWivid committed Nov 11, 2024
1 parent da059e8 commit be53fb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/f5_tts/infer/infer_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,17 +757,22 @@ def load_last_used_custom():
"hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt",
]

def switch_tts_model(new_choice, custom_ckpt_path, custom_vocab_path):
def switch_tts_model(new_choice):
global tts_model_choice
if new_choice == "Custom":
if new_choice == "Custom": # override in case webpage is refreshed
custom_ckpt_path, custom_vocab_path = load_last_used_custom()
tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path]
with open(last_used_custom, "w") as f:
f.write(f"{custom_ckpt_path},{custom_vocab_path}")
return gr.update(visible=True), gr.update(visible=True)
return gr.update(visible=True, value=custom_ckpt_path), gr.update(visible=True, value=custom_vocab_path)
else:
tts_model_choice = new_choice
return gr.update(visible=False), gr.update(visible=False)

def set_custom_model(custom_ckpt_path, custom_vocab_path):
global tts_model_choice
tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path]
with open(last_used_custom, "w") as f:
f.write(f"{custom_ckpt_path},{custom_vocab_path}")

with gr.Row():
if not USING_SPACES:
choose_tts_model = gr.Radio(
Expand All @@ -794,20 +799,18 @@ def switch_tts_model(new_choice, custom_ckpt_path, custom_vocab_path):

choose_tts_model.change(
switch_tts_model,
inputs=[choose_tts_model, custom_ckpt_path, custom_vocab_path],
inputs=[choose_tts_model],
outputs=[custom_ckpt_path, custom_vocab_path],
show_progress="hidden",
)
custom_ckpt_path.change(
switch_tts_model,
inputs=[choose_tts_model, custom_ckpt_path, custom_vocab_path],
outputs=[custom_ckpt_path, custom_vocab_path],
set_custom_model,
inputs=[custom_ckpt_path, custom_vocab_path],
show_progress="hidden",
)
custom_vocab_path.change(
switch_tts_model,
inputs=[choose_tts_model, custom_ckpt_path, custom_vocab_path],
outputs=[custom_ckpt_path, custom_vocab_path],
set_custom_model,
inputs=[custom_ckpt_path, custom_vocab_path],
show_progress="hidden",
)

Expand Down
2 changes: 1 addition & 1 deletion src/f5_tts/infer/utils_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def load_model(
tokenizer = "custom"

print("\nvocab : ", vocab_file)
print("tokenizer : ", tokenizer)
print("token : ", tokenizer)
print("model : ", ckpt_path, "\n")

vocab_char_map, vocab_size = get_tokenizer(vocab_file, tokenizer)
Expand Down

0 comments on commit be53fb1

Please sign in to comment.