save_config_gradio.py 986 B

12345678910111213141516171819202122232425262728293031
  1. from tts_webui.config._save_config import _save_config
  2. from tts_webui.config.config import config
  3. from typing import List, Any
  4. def _convert_empty_strings_to_none(dictionary: dict):
  5. for key, value in dictionary.items():
  6. if value == "":
  7. dictionary[key] = None
  8. def _recreate_ui_dict(keys: List[str], inputs: List[Any]):
  9. return {keys[i]: value for i, value in enumerate(inputs)}
  10. def _generate_gradio_settings(keys: List[str], inputs: List[Any]):
  11. gradio_interface_options = _recreate_ui_dict(keys, inputs)
  12. _convert_empty_strings_to_none(gradio_interface_options)
  13. gradio_interface_options["server_port"] = int(
  14. gradio_interface_options["server_port"]
  15. )
  16. return gradio_interface_options
  17. def save_config_gradio(keys: List[str], inputs: List[Any]):
  18. global config
  19. config["gradio_interface_options"] = _generate_gradio_settings(keys, inputs)
  20. _save_config(config)
  21. return f"Saved {config['gradio_interface_options']}"