tortoise_model_settings_ui.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from tts_webui.tortoise.gen_tortoise import (
  2. TORTOISE_LOCAL_MODELS_DIR,
  3. get_model_list,
  4. switch_model,
  5. unload_tortoise_model,
  6. )
  7. from tts_webui.tortoise.gr_reload_button import gr_open_button_simple, gr_reload_button
  8. import gradio as gr
  9. def tortoise_model_settings_ui_inner():
  10. with gr.Row():
  11. model = gr.Dropdown(
  12. choices=get_model_list(),
  13. value="Default",
  14. show_label=False,
  15. container=False,
  16. )
  17. gr_open_button_simple(
  18. TORTOISE_LOCAL_MODELS_DIR, api_name="tortoise_open_models"
  19. )
  20. gr_reload_button().click(
  21. fn=lambda: gr.Dropdown(choices=get_model_list()),
  22. outputs=[model],
  23. api_name="tortoise_refresh_models",
  24. )
  25. with gr.Row():
  26. kv_cache = gr.Checkbox(label="KV Cache", value=False)
  27. use_deepspeed = gr.Checkbox(label="Use Deepspeed", value=False)
  28. half = gr.Checkbox(label="Half", value=False)
  29. use_basic_cleaners = gr.Checkbox(label="Use basic cleaners", value=False)
  30. tokenizer = gr.File(
  31. label="Tokenizer",
  32. file_types=[".json"],
  33. )
  34. unload_model = gr.Button(
  35. "Unload model",
  36. variant="secondary",
  37. )
  38. unload_model.click(
  39. fn=unload_tortoise_model,
  40. api_name="tortoise_unload_model",
  41. )
  42. apply_model_settings = gr.Button(
  43. "Apply model settings",
  44. variant="secondary",
  45. )
  46. apply_model_settings.click(
  47. fn=switch_model,
  48. inputs=[model, kv_cache, use_deepspeed, half, tokenizer, use_basic_cleaners],
  49. outputs=[model],
  50. api_name="tortoise_apply_model_settings",
  51. )
  52. model.select(
  53. fn=switch_model,
  54. inputs=[model, kv_cache, use_deepspeed, half, tokenizer, use_basic_cleaners],
  55. outputs=[model],
  56. )
  57. return model
  58. def tortoise_model_settings_ui():
  59. with gr.Column():
  60. gr.Markdown("Model")
  61. with gr.Column():
  62. return tortoise_model_settings_ui_inner()