parse_or_set_seed.py 560 B

123456789101112131415161718
  1. from typing import Union
  2. from tts_webui.bark.generate_random_seed import generate_random_seed
  3. from tts_webui.utils.set_seed import set_seed
  4. def parse_or_generate_seed(seed: Union[str, int, None], index: int) -> int:
  5. if seed is not None:
  6. seed = int(seed)
  7. if seed == -1:
  8. seed = generate_random_seed()
  9. indexed_seed = seed + index # type: ignore
  10. return indexed_seed
  11. def parse_or_set_seed(seed: Union[str, int, None], index: int) -> int:
  12. seed = parse_or_generate_seed(seed, index)
  13. set_seed(seed)
  14. return seed