xinference 0.16.3__py3-none-any.whl → 1.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xinference might be problematic. Click here for more details.

Files changed (373) hide show
  1. xinference/_compat.py +24 -2
  2. xinference/_version.py +3 -3
  3. xinference/api/restful_api.py +219 -77
  4. xinference/client/restful/restful_client.py +47 -2
  5. xinference/constants.py +1 -0
  6. xinference/core/chat_interface.py +6 -1
  7. xinference/core/model.py +124 -34
  8. xinference/core/supervisor.py +180 -12
  9. xinference/core/utils.py +73 -4
  10. xinference/core/worker.py +102 -4
  11. xinference/deploy/cmdline.py +3 -1
  12. xinference/deploy/test/test_cmdline.py +56 -0
  13. xinference/isolation.py +24 -0
  14. xinference/model/audio/__init__.py +12 -0
  15. xinference/model/audio/core.py +37 -4
  16. xinference/model/audio/cosyvoice.py +39 -6
  17. xinference/model/audio/f5tts.py +200 -0
  18. xinference/model/audio/f5tts_mlx.py +260 -0
  19. xinference/model/audio/fish_speech.py +70 -110
  20. xinference/model/audio/melotts.py +110 -0
  21. xinference/model/audio/model_spec.json +179 -3
  22. xinference/model/audio/model_spec_modelscope.json +27 -0
  23. xinference/model/audio/utils.py +32 -0
  24. xinference/model/audio/whisper.py +35 -10
  25. xinference/model/audio/whisper_mlx.py +208 -0
  26. xinference/model/embedding/core.py +322 -6
  27. xinference/model/embedding/model_spec.json +8 -1
  28. xinference/model/embedding/model_spec_modelscope.json +9 -1
  29. xinference/model/image/core.py +69 -1
  30. xinference/model/image/model_spec.json +145 -4
  31. xinference/model/image/model_spec_modelscope.json +150 -4
  32. xinference/model/image/stable_diffusion/core.py +50 -15
  33. xinference/model/llm/__init__.py +6 -2
  34. xinference/model/llm/llm_family.json +1055 -93
  35. xinference/model/llm/llm_family.py +15 -36
  36. xinference/model/llm/llm_family_modelscope.json +1031 -78
  37. xinference/model/llm/memory.py +1 -1
  38. xinference/model/llm/mlx/core.py +285 -47
  39. xinference/model/llm/sglang/core.py +2 -0
  40. xinference/model/llm/transformers/chatglm.py +9 -5
  41. xinference/model/llm/transformers/cogagent.py +272 -0
  42. xinference/model/llm/transformers/core.py +3 -0
  43. xinference/model/llm/transformers/glm_edge_v.py +230 -0
  44. xinference/model/llm/transformers/qwen2_vl.py +12 -1
  45. xinference/model/llm/transformers/utils.py +16 -8
  46. xinference/model/llm/utils.py +55 -4
  47. xinference/model/llm/vllm/core.py +137 -12
  48. xinference/model/llm/vllm/xavier/__init__.py +13 -0
  49. xinference/model/llm/vllm/xavier/allocator.py +74 -0
  50. xinference/model/llm/vllm/xavier/block.py +111 -0
  51. xinference/model/llm/vllm/xavier/block_manager.py +71 -0
  52. xinference/model/llm/vllm/xavier/block_tracker.py +129 -0
  53. xinference/model/llm/vllm/xavier/collective.py +74 -0
  54. xinference/model/llm/vllm/xavier/collective_manager.py +147 -0
  55. xinference/model/llm/vllm/xavier/engine.py +247 -0
  56. xinference/model/llm/vllm/xavier/executor.py +134 -0
  57. xinference/model/llm/vllm/xavier/scheduler.py +438 -0
  58. xinference/model/llm/vllm/xavier/test/__init__.py +13 -0
  59. xinference/model/llm/vllm/xavier/test/test_xavier.py +147 -0
  60. xinference/model/llm/vllm/xavier/transfer.py +319 -0
  61. xinference/model/rerank/core.py +11 -4
  62. xinference/model/video/diffusers.py +14 -0
  63. xinference/model/video/model_spec.json +15 -0
  64. xinference/model/video/model_spec_modelscope.json +16 -0
  65. xinference/thirdparty/cosyvoice/bin/average_model.py +92 -0
  66. xinference/thirdparty/cosyvoice/bin/export_jit.py +12 -2
  67. xinference/thirdparty/cosyvoice/bin/export_onnx.py +112 -0
  68. xinference/thirdparty/cosyvoice/bin/export_trt.sh +9 -0
  69. xinference/thirdparty/cosyvoice/bin/inference.py +5 -7
  70. xinference/thirdparty/cosyvoice/bin/spk2info.pt +0 -0
  71. xinference/thirdparty/cosyvoice/bin/train.py +42 -8
  72. xinference/thirdparty/cosyvoice/cli/cosyvoice.py +96 -25
  73. xinference/thirdparty/cosyvoice/cli/frontend.py +77 -30
  74. xinference/thirdparty/cosyvoice/cli/model.py +330 -80
  75. xinference/thirdparty/cosyvoice/dataset/dataset.py +6 -2
  76. xinference/thirdparty/cosyvoice/dataset/processor.py +76 -14
  77. xinference/thirdparty/cosyvoice/flow/decoder.py +92 -13
  78. xinference/thirdparty/cosyvoice/flow/flow.py +99 -9
  79. xinference/thirdparty/cosyvoice/flow/flow_matching.py +110 -13
  80. xinference/thirdparty/cosyvoice/flow/length_regulator.py +5 -4
  81. xinference/thirdparty/cosyvoice/hifigan/discriminator.py +140 -0
  82. xinference/thirdparty/cosyvoice/hifigan/generator.py +58 -42
  83. xinference/thirdparty/cosyvoice/hifigan/hifigan.py +67 -0
  84. xinference/thirdparty/cosyvoice/llm/llm.py +139 -6
  85. xinference/thirdparty/cosyvoice/tokenizer/assets/multilingual_zh_ja_yue_char_del.tiktoken +58836 -0
  86. xinference/thirdparty/cosyvoice/tokenizer/tokenizer.py +279 -0
  87. xinference/thirdparty/cosyvoice/transformer/embedding.py +2 -2
  88. xinference/thirdparty/cosyvoice/transformer/encoder_layer.py +7 -7
  89. xinference/thirdparty/cosyvoice/transformer/upsample_encoder.py +318 -0
  90. xinference/thirdparty/cosyvoice/utils/common.py +28 -1
  91. xinference/thirdparty/cosyvoice/utils/executor.py +69 -7
  92. xinference/thirdparty/cosyvoice/utils/file_utils.py +2 -12
  93. xinference/thirdparty/cosyvoice/utils/frontend_utils.py +9 -5
  94. xinference/thirdparty/cosyvoice/utils/losses.py +20 -0
  95. xinference/thirdparty/cosyvoice/utils/scheduler.py +1 -2
  96. xinference/thirdparty/cosyvoice/utils/train_utils.py +101 -45
  97. xinference/thirdparty/f5_tts/api.py +166 -0
  98. xinference/thirdparty/f5_tts/configs/E2TTS_Base_train.yaml +44 -0
  99. xinference/thirdparty/f5_tts/configs/E2TTS_Small_train.yaml +44 -0
  100. xinference/thirdparty/f5_tts/configs/F5TTS_Base_train.yaml +46 -0
  101. xinference/thirdparty/f5_tts/configs/F5TTS_Small_train.yaml +46 -0
  102. xinference/thirdparty/f5_tts/eval/README.md +49 -0
  103. xinference/thirdparty/f5_tts/eval/ecapa_tdnn.py +330 -0
  104. xinference/thirdparty/f5_tts/eval/eval_infer_batch.py +207 -0
  105. xinference/thirdparty/f5_tts/eval/eval_infer_batch.sh +13 -0
  106. xinference/thirdparty/f5_tts/eval/eval_librispeech_test_clean.py +84 -0
  107. xinference/thirdparty/f5_tts/eval/eval_seedtts_testset.py +84 -0
  108. xinference/thirdparty/f5_tts/eval/utils_eval.py +405 -0
  109. xinference/thirdparty/f5_tts/infer/README.md +191 -0
  110. xinference/thirdparty/f5_tts/infer/SHARED.md +74 -0
  111. xinference/thirdparty/f5_tts/infer/examples/basic/basic.toml +11 -0
  112. xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_en.wav +0 -0
  113. xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_zh.wav +0 -0
  114. xinference/thirdparty/f5_tts/infer/examples/multi/country.flac +0 -0
  115. xinference/thirdparty/f5_tts/infer/examples/multi/main.flac +0 -0
  116. xinference/thirdparty/f5_tts/infer/examples/multi/story.toml +19 -0
  117. xinference/thirdparty/f5_tts/infer/examples/multi/story.txt +1 -0
  118. xinference/thirdparty/f5_tts/infer/examples/multi/town.flac +0 -0
  119. xinference/thirdparty/f5_tts/infer/examples/vocab.txt +2545 -0
  120. xinference/thirdparty/f5_tts/infer/infer_cli.py +226 -0
  121. xinference/thirdparty/f5_tts/infer/infer_gradio.py +851 -0
  122. xinference/thirdparty/f5_tts/infer/speech_edit.py +193 -0
  123. xinference/thirdparty/f5_tts/infer/utils_infer.py +538 -0
  124. xinference/thirdparty/f5_tts/model/__init__.py +10 -0
  125. xinference/thirdparty/f5_tts/model/backbones/README.md +20 -0
  126. xinference/thirdparty/f5_tts/model/backbones/dit.py +163 -0
  127. xinference/thirdparty/f5_tts/model/backbones/mmdit.py +146 -0
  128. xinference/thirdparty/f5_tts/model/backbones/unett.py +219 -0
  129. xinference/thirdparty/f5_tts/model/cfm.py +285 -0
  130. xinference/thirdparty/f5_tts/model/dataset.py +319 -0
  131. xinference/thirdparty/f5_tts/model/modules.py +658 -0
  132. xinference/thirdparty/f5_tts/model/trainer.py +366 -0
  133. xinference/thirdparty/f5_tts/model/utils.py +185 -0
  134. xinference/thirdparty/f5_tts/scripts/count_max_epoch.py +33 -0
  135. xinference/thirdparty/f5_tts/scripts/count_params_gflops.py +39 -0
  136. xinference/thirdparty/f5_tts/socket_server.py +159 -0
  137. xinference/thirdparty/f5_tts/train/README.md +77 -0
  138. xinference/thirdparty/f5_tts/train/datasets/prepare_csv_wavs.py +139 -0
  139. xinference/thirdparty/f5_tts/train/datasets/prepare_emilia.py +230 -0
  140. xinference/thirdparty/f5_tts/train/datasets/prepare_libritts.py +92 -0
  141. xinference/thirdparty/f5_tts/train/datasets/prepare_ljspeech.py +65 -0
  142. xinference/thirdparty/f5_tts/train/datasets/prepare_wenetspeech4tts.py +125 -0
  143. xinference/thirdparty/f5_tts/train/finetune_cli.py +174 -0
  144. xinference/thirdparty/f5_tts/train/finetune_gradio.py +1846 -0
  145. xinference/thirdparty/f5_tts/train/train.py +75 -0
  146. xinference/thirdparty/fish_speech/fish_speech/conversation.py +266 -1
  147. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/en_US.json +2 -1
  148. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/es_ES.json +2 -1
  149. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/ja_JP.json +2 -2
  150. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/ko_KR.json +123 -0
  151. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/zh_CN.json +2 -1
  152. xinference/thirdparty/fish_speech/fish_speech/models/text2semantic/llama.py +137 -29
  153. xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/firefly.py +9 -9
  154. xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/fsq.py +1 -1
  155. xinference/thirdparty/fish_speech/fish_speech/text/clean.py +17 -11
  156. xinference/thirdparty/fish_speech/fish_speech/text/spliter.py +1 -1
  157. xinference/thirdparty/fish_speech/fish_speech/tokenizer.py +152 -0
  158. xinference/thirdparty/fish_speech/fish_speech/train.py +2 -2
  159. xinference/thirdparty/fish_speech/fish_speech/utils/__init__.py +2 -1
  160. xinference/thirdparty/fish_speech/fish_speech/utils/utils.py +22 -0
  161. xinference/thirdparty/fish_speech/fish_speech/webui/launch_utils.py +1 -1
  162. xinference/thirdparty/fish_speech/fish_speech/webui/manage.py +2 -2
  163. xinference/thirdparty/fish_speech/tools/{post_api.py → api_client.py} +34 -18
  164. xinference/thirdparty/fish_speech/tools/api_server.py +98 -0
  165. xinference/thirdparty/fish_speech/tools/download_models.py +5 -5
  166. xinference/thirdparty/fish_speech/tools/e2e_webui.py +232 -0
  167. xinference/thirdparty/fish_speech/tools/fish_e2e.py +298 -0
  168. xinference/thirdparty/fish_speech/tools/inference_engine/__init__.py +192 -0
  169. xinference/thirdparty/fish_speech/tools/inference_engine/reference_loader.py +125 -0
  170. xinference/thirdparty/fish_speech/tools/inference_engine/utils.py +39 -0
  171. xinference/thirdparty/fish_speech/tools/inference_engine/vq_manager.py +57 -0
  172. xinference/thirdparty/fish_speech/tools/llama/eval_in_context.py +2 -2
  173. xinference/thirdparty/fish_speech/tools/llama/generate.py +484 -72
  174. xinference/thirdparty/fish_speech/tools/run_webui.py +104 -0
  175. xinference/thirdparty/fish_speech/tools/schema.py +170 -0
  176. xinference/thirdparty/fish_speech/tools/server/agent/__init__.py +57 -0
  177. xinference/thirdparty/fish_speech/tools/server/agent/generate.py +119 -0
  178. xinference/thirdparty/fish_speech/tools/server/agent/generation_utils.py +122 -0
  179. xinference/thirdparty/fish_speech/tools/server/agent/pre_generation_utils.py +72 -0
  180. xinference/thirdparty/fish_speech/tools/server/api_utils.py +75 -0
  181. xinference/thirdparty/fish_speech/tools/server/exception_handler.py +27 -0
  182. xinference/thirdparty/fish_speech/tools/server/inference.py +45 -0
  183. xinference/thirdparty/fish_speech/tools/server/model_manager.py +122 -0
  184. xinference/thirdparty/fish_speech/tools/server/model_utils.py +129 -0
  185. xinference/thirdparty/fish_speech/tools/server/views.py +246 -0
  186. xinference/thirdparty/fish_speech/tools/vqgan/extract_vq.py +7 -1
  187. xinference/thirdparty/fish_speech/tools/vqgan/inference.py +2 -3
  188. xinference/thirdparty/fish_speech/tools/webui/__init__.py +173 -0
  189. xinference/thirdparty/fish_speech/tools/webui/inference.py +91 -0
  190. xinference/thirdparty/fish_speech/tools/webui/variables.py +14 -0
  191. xinference/thirdparty/matcha/utils/utils.py +2 -2
  192. xinference/thirdparty/melo/api.py +135 -0
  193. xinference/thirdparty/melo/app.py +61 -0
  194. xinference/thirdparty/melo/attentions.py +459 -0
  195. xinference/thirdparty/melo/commons.py +160 -0
  196. xinference/thirdparty/melo/configs/config.json +94 -0
  197. xinference/thirdparty/melo/data/example/metadata.list +20 -0
  198. xinference/thirdparty/melo/data_utils.py +413 -0
  199. xinference/thirdparty/melo/download_utils.py +67 -0
  200. xinference/thirdparty/melo/infer.py +25 -0
  201. xinference/thirdparty/melo/init_downloads.py +14 -0
  202. xinference/thirdparty/melo/losses.py +58 -0
  203. xinference/thirdparty/melo/main.py +36 -0
  204. xinference/thirdparty/melo/mel_processing.py +174 -0
  205. xinference/thirdparty/melo/models.py +1030 -0
  206. xinference/thirdparty/melo/modules.py +598 -0
  207. xinference/thirdparty/melo/monotonic_align/__init__.py +16 -0
  208. xinference/thirdparty/melo/monotonic_align/core.py +46 -0
  209. xinference/thirdparty/melo/preprocess_text.py +135 -0
  210. xinference/thirdparty/melo/split_utils.py +174 -0
  211. xinference/thirdparty/melo/text/__init__.py +35 -0
  212. xinference/thirdparty/melo/text/chinese.py +199 -0
  213. xinference/thirdparty/melo/text/chinese_bert.py +107 -0
  214. xinference/thirdparty/melo/text/chinese_mix.py +253 -0
  215. xinference/thirdparty/melo/text/cleaner.py +36 -0
  216. xinference/thirdparty/melo/text/cleaner_multiling.py +110 -0
  217. xinference/thirdparty/melo/text/cmudict.rep +129530 -0
  218. xinference/thirdparty/melo/text/cmudict_cache.pickle +0 -0
  219. xinference/thirdparty/melo/text/english.py +284 -0
  220. xinference/thirdparty/melo/text/english_bert.py +39 -0
  221. xinference/thirdparty/melo/text/english_utils/abbreviations.py +35 -0
  222. xinference/thirdparty/melo/text/english_utils/number_norm.py +97 -0
  223. xinference/thirdparty/melo/text/english_utils/time_norm.py +47 -0
  224. xinference/thirdparty/melo/text/es_phonemizer/base.py +140 -0
  225. xinference/thirdparty/melo/text/es_phonemizer/cleaner.py +109 -0
  226. xinference/thirdparty/melo/text/es_phonemizer/es_symbols.json +79 -0
  227. xinference/thirdparty/melo/text/es_phonemizer/es_symbols.txt +1 -0
  228. xinference/thirdparty/melo/text/es_phonemizer/es_symbols_v2.json +83 -0
  229. xinference/thirdparty/melo/text/es_phonemizer/es_to_ipa.py +12 -0
  230. xinference/thirdparty/melo/text/es_phonemizer/example_ipa.txt +400 -0
  231. xinference/thirdparty/melo/text/es_phonemizer/gruut_wrapper.py +253 -0
  232. xinference/thirdparty/melo/text/es_phonemizer/punctuation.py +174 -0
  233. xinference/thirdparty/melo/text/es_phonemizer/spanish_symbols.txt +1 -0
  234. xinference/thirdparty/melo/text/es_phonemizer/test.ipynb +124 -0
  235. xinference/thirdparty/melo/text/fr_phonemizer/base.py +140 -0
  236. xinference/thirdparty/melo/text/fr_phonemizer/cleaner.py +122 -0
  237. xinference/thirdparty/melo/text/fr_phonemizer/en_symbols.json +78 -0
  238. xinference/thirdparty/melo/text/fr_phonemizer/example_ipa.txt +1 -0
  239. xinference/thirdparty/melo/text/fr_phonemizer/fr_symbols.json +89 -0
  240. xinference/thirdparty/melo/text/fr_phonemizer/fr_to_ipa.py +30 -0
  241. xinference/thirdparty/melo/text/fr_phonemizer/french_abbreviations.py +48 -0
  242. xinference/thirdparty/melo/text/fr_phonemizer/french_symbols.txt +1 -0
  243. xinference/thirdparty/melo/text/fr_phonemizer/gruut_wrapper.py +258 -0
  244. xinference/thirdparty/melo/text/fr_phonemizer/punctuation.py +172 -0
  245. xinference/thirdparty/melo/text/french.py +94 -0
  246. xinference/thirdparty/melo/text/french_bert.py +39 -0
  247. xinference/thirdparty/melo/text/japanese.py +647 -0
  248. xinference/thirdparty/melo/text/japanese_bert.py +49 -0
  249. xinference/thirdparty/melo/text/ko_dictionary.py +44 -0
  250. xinference/thirdparty/melo/text/korean.py +192 -0
  251. xinference/thirdparty/melo/text/opencpop-strict.txt +429 -0
  252. xinference/thirdparty/melo/text/spanish.py +122 -0
  253. xinference/thirdparty/melo/text/spanish_bert.py +39 -0
  254. xinference/thirdparty/melo/text/symbols.py +290 -0
  255. xinference/thirdparty/melo/text/tone_sandhi.py +769 -0
  256. xinference/thirdparty/melo/train.py +635 -0
  257. xinference/thirdparty/melo/train.sh +19 -0
  258. xinference/thirdparty/melo/transforms.py +209 -0
  259. xinference/thirdparty/melo/utils.py +424 -0
  260. xinference/types.py +17 -1
  261. xinference/web/ui/build/asset-manifest.json +6 -6
  262. xinference/web/ui/build/index.html +1 -1
  263. xinference/web/ui/build/static/css/main.51a587ff.css +2 -0
  264. xinference/web/ui/build/static/css/main.51a587ff.css.map +1 -0
  265. xinference/web/ui/build/static/js/main.b0936c54.js +3 -0
  266. xinference/web/ui/build/static/js/main.b0936c54.js.map +1 -0
  267. xinference/web/ui/node_modules/.cache/babel-loader/03c4052f1b91f6ba0c5389bdcf49c43319b4076c08e4b8585dab312538ae290a.json +1 -0
  268. xinference/web/ui/node_modules/.cache/babel-loader/1786b83003b8e9605a0f5f855a185d4d16e38fc893dfb326a2a9cca206b4240a.json +1 -0
  269. xinference/web/ui/node_modules/.cache/babel-loader/17cbc181dd674b9150b80c73ed6a82656de0082d857f6e5f66d9716129ac0b38.json +1 -0
  270. xinference/web/ui/node_modules/.cache/babel-loader/185ceb8872d562e032b47e79df6a45670e06345b8ed70aad1a131e0476783c5c.json +1 -0
  271. xinference/web/ui/node_modules/.cache/babel-loader/26b8c9f34b0bed789b3a833767672e39302d1e0c09b4276f4d58d1df7b6bd93b.json +1 -0
  272. xinference/web/ui/node_modules/.cache/babel-loader/2b484da66c724d0d56a40849c109327408796a668b1381511b6e9e03baa48658.json +1 -0
  273. xinference/web/ui/node_modules/.cache/babel-loader/2cbbbce9b84df73330d4c42b82436ed881b3847628f2fbc346aa62e2859fd88c.json +1 -0
  274. xinference/web/ui/node_modules/.cache/babel-loader/2ec9b14431ed33ce6901bf9f27007be4e6e472709c99d6e22b50ce528e4b78ee.json +1 -0
  275. xinference/web/ui/node_modules/.cache/babel-loader/3b966db018f96be4a055d6ca205f0990d4d0b370e2980c17d8bca2c9a021819c.json +1 -0
  276. xinference/web/ui/node_modules/.cache/babel-loader/3eefb411b24c2b3ce053570ef50daccf154022f0e168be5ed0fec21394baf9f4.json +1 -0
  277. xinference/web/ui/node_modules/.cache/babel-loader/522b229e3cac219123f0d69673f5570e191c2d2a505dc65b312d336eae2279c0.json +1 -0
  278. xinference/web/ui/node_modules/.cache/babel-loader/52e45f17ba300580ea3fcc9f9228ccba194bb092b76f25e9255af311f8b05aab.json +1 -0
  279. xinference/web/ui/node_modules/.cache/babel-loader/5a0bc4631f936459afc1a3b1d3ec2420118b1f00e11f60ccac3e08088f3f27a8.json +1 -0
  280. xinference/web/ui/node_modules/.cache/babel-loader/611fa2c6c53b66039991d06dfb0473b5ab37fc63b4564e0f6e1718523768a045.json +1 -0
  281. xinference/web/ui/node_modules/.cache/babel-loader/6329bc76c406fe5eb305412383fbde5950f847bb5e43261f73f37622c365acb4.json +1 -0
  282. xinference/web/ui/node_modules/.cache/babel-loader/63c8e07687ea53a4f8a910ee5e42e0eb26cd1acbfbe820f3e3248a786ee51401.json +1 -0
  283. xinference/web/ui/node_modules/.cache/babel-loader/69b2d5001684174ec9da57e07914eed3eac4960018bceb6cbfa801d861301d7c.json +1 -0
  284. xinference/web/ui/node_modules/.cache/babel-loader/710c1acda69e561e30a933b98c6a56d50197868b15c21e2aad55ab6d46649eb6.json +1 -0
  285. xinference/web/ui/node_modules/.cache/babel-loader/720deca1fce5a1dc5056048fa8258fd138a82ea855f350b6613f104a73fb761f.json +1 -0
  286. xinference/web/ui/node_modules/.cache/babel-loader/76a23b92d26a499c57e61eea2b895fbc9771bd0849a72e66f8e633192017978b.json +1 -0
  287. xinference/web/ui/node_modules/.cache/babel-loader/858063f23b34dfe600254eb5afd85518b0002ec4b30b7386616c45600826e3b2.json +1 -0
  288. xinference/web/ui/node_modules/.cache/babel-loader/920b82c1c89124cf217109eeedbfcd3aae3b917be50c9dfb6bbb4ce26bdfd2e7.json +1 -0
  289. xinference/web/ui/node_modules/.cache/babel-loader/94d8b7aeb0076f2ce07db598cea0e87b13bc8d5614eb530b8d6e696c2daf6f88.json +1 -0
  290. xinference/web/ui/node_modules/.cache/babel-loader/9e917fe7022d01b2ccbe5cc0ce73d70bb72bee584ff293bad71bdff6695dee28.json +1 -0
  291. xinference/web/ui/node_modules/.cache/babel-loader/9f28fdb8399f1d0474f0aca86f1658dc94f5bf0c90f6146352de150692de8862.json +1 -0
  292. xinference/web/ui/node_modules/.cache/babel-loader/a0dfafa06b2bb7cba8cad41c482503f61944f759f4318139362602ef5cc47ccb.json +1 -0
  293. xinference/web/ui/node_modules/.cache/babel-loader/a3ff866acddf34917a7ee399e0e571a4dfd8ba66d5057db885f243e16a6eb17d.json +1 -0
  294. xinference/web/ui/node_modules/.cache/babel-loader/afb8084f539534cd594755ea2205ecd5bd1f62dddcfdf75a2eace59a28131278.json +1 -0
  295. xinference/web/ui/node_modules/.cache/babel-loader/b57b1438b77294c1f3f6cfce12ac487d8106c6f016975ba0aec94d98997e2e1e.json +1 -0
  296. xinference/web/ui/node_modules/.cache/babel-loader/b9917b0bf8e4d55ccbac1c334aa04d6ff3c5b6ed9e5d38b9ea2c687fa7d3f5a9.json +1 -0
  297. xinference/web/ui/node_modules/.cache/babel-loader/bbcc94b0149963d1d6f267ee1f4f03d3925b758392ce2f516c3fe8af0e0169fc.json +1 -0
  298. xinference/web/ui/node_modules/.cache/babel-loader/bdee44abeadc4abc17d41c52eb49c6e19a4b1a267b6e16876ce91bdeeebfc52d.json +1 -0
  299. xinference/web/ui/node_modules/.cache/babel-loader/beb112b70f4a56db95920a9e20efb6c97c37b68450716730217a9ee1a9ae92be.json +1 -0
  300. xinference/web/ui/node_modules/.cache/babel-loader/c88db97be0cdf440193b3995996e83510a04cb00048135485fc0e26d197e80b5.json +1 -0
  301. xinference/web/ui/node_modules/.cache/babel-loader/d49e5314d34310a62d01a03067ce1bec5da00abce84c5196aa9c6842fa79a430.json +1 -0
  302. xinference/web/ui/node_modules/.cache/babel-loader/d7664d18c4ddbad9c3a6a31b91f7c00fb0dde804608674a9860ee50f33e54708.json +1 -0
  303. xinference/web/ui/node_modules/.cache/babel-loader/d9072c318b819b7c90a0f7e9cc0b6413b4dbeb8e9859898e53d75ea882fcde99.json +1 -0
  304. xinference/web/ui/node_modules/.cache/babel-loader/db16a983bc08a05f0439cc61ca0840e49e1d8400eef678909f16c032a418a3d6.json +1 -0
  305. xinference/web/ui/node_modules/.cache/babel-loader/dc249829767b8abcbc3677e0b07b6d3ecbfdfe6d08cfe23a665eb33373a9aa9d.json +1 -0
  306. xinference/web/ui/node_modules/.cache/babel-loader/e242c583c2dbc2784f0fcf513523975f7d5df447e106c1c17e49e8578a6fc3ed.json +1 -0
  307. xinference/web/ui/node_modules/.cache/babel-loader/eac5f1296513e69e4b96f750ddccd4d0264e2bae4e4c449144e83274a48698d9.json +1 -0
  308. xinference/web/ui/node_modules/.cache/babel-loader/ed57202cb79649bb716400436590245547df241988fc7c8e1d85d132299542d2.json +1 -0
  309. xinference/web/ui/node_modules/.cache/babel-loader/f125bf72e773a14cdaebd0c343e80adb909d12e317ee5c00cd4a57442fbe2c62.json +1 -0
  310. xinference/web/ui/node_modules/.cache/babel-loader/f91af913d7f91c410719ab13136aaed3aaf0f8dda06652f25c42cb5231587398.json +1 -0
  311. xinference/web/ui/node_modules/.package-lock.json +67 -3
  312. xinference/web/ui/node_modules/@babel/runtime/package.json +592 -538
  313. xinference/web/ui/node_modules/html-parse-stringify/package.json +50 -0
  314. xinference/web/ui/node_modules/i18next/dist/esm/package.json +1 -0
  315. xinference/web/ui/node_modules/i18next/package.json +129 -0
  316. xinference/web/ui/node_modules/react-i18next/.eslintrc.json +74 -0
  317. xinference/web/ui/node_modules/react-i18next/dist/es/package.json +1 -0
  318. xinference/web/ui/node_modules/react-i18next/package.json +162 -0
  319. xinference/web/ui/node_modules/void-elements/package.json +34 -0
  320. xinference/web/ui/package-lock.json +69 -3
  321. xinference/web/ui/package.json +2 -0
  322. xinference/web/ui/src/locales/en.json +186 -0
  323. xinference/web/ui/src/locales/zh.json +186 -0
  324. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/METADATA +96 -36
  325. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/RECORD +335 -146
  326. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/WHEEL +1 -1
  327. xinference/thirdparty/cosyvoice/bin/export_trt.py +0 -8
  328. xinference/thirdparty/fish_speech/fish_speech/configs/lora/__init__.py +0 -0
  329. xinference/thirdparty/fish_speech/fish_speech/datasets/__init__.py +0 -0
  330. xinference/thirdparty/fish_speech/fish_speech/datasets/protos/__init__.py +0 -0
  331. xinference/thirdparty/fish_speech/fish_speech/i18n/locale/__init__.py +0 -0
  332. xinference/thirdparty/fish_speech/fish_speech/models/__init__.py +0 -0
  333. xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/__init__.py +0 -0
  334. xinference/thirdparty/fish_speech/fish_speech/webui/__init__.py +0 -0
  335. xinference/thirdparty/fish_speech/tools/__init__.py +0 -0
  336. xinference/thirdparty/fish_speech/tools/api.py +0 -440
  337. xinference/thirdparty/fish_speech/tools/commons.py +0 -35
  338. xinference/thirdparty/fish_speech/tools/llama/__init__.py +0 -0
  339. xinference/thirdparty/fish_speech/tools/msgpack_api.py +0 -34
  340. xinference/thirdparty/fish_speech/tools/vqgan/__init__.py +0 -0
  341. xinference/thirdparty/fish_speech/tools/webui.py +0 -485
  342. xinference/web/ui/build/static/css/main.5061c4c3.css +0 -2
  343. xinference/web/ui/build/static/css/main.5061c4c3.css.map +0 -1
  344. xinference/web/ui/build/static/js/main.2f269bb3.js +0 -3
  345. xinference/web/ui/build/static/js/main.2f269bb3.js.map +0 -1
  346. xinference/web/ui/node_modules/.cache/babel-loader/07ce9e632e6aff24d7aa3ad8e48224433bbfeb0d633fca723453f1fcae0c9f1c.json +0 -1
  347. xinference/web/ui/node_modules/.cache/babel-loader/1130403f9e46f5738a23b45ac59b57de8f360c908c713e2c0670c2cce9bd367a.json +0 -1
  348. xinference/web/ui/node_modules/.cache/babel-loader/131091b25d26b17cdca187d7542a21475c211138d900cf667682260e76ef9463.json +0 -1
  349. xinference/web/ui/node_modules/.cache/babel-loader/1f269fb2a368363c1cb2237825f1dba093b6bdd8c44cc05954fd19ec2c1fff03.json +0 -1
  350. xinference/web/ui/node_modules/.cache/babel-loader/331312668fa8bd3d7401818f4a25fa98135d7f61371cd6bfff78b18cf4fbdd92.json +0 -1
  351. xinference/web/ui/node_modules/.cache/babel-loader/40f17338fc75ae095de7d2b4d8eae0d5ca0193a7e2bcece4ee745b22a7a2f4b7.json +0 -1
  352. xinference/web/ui/node_modules/.cache/babel-loader/4de9a6942c5f1749d6cbfdd54279699975f16016b182848bc253886f52ec2ec3.json +0 -1
  353. xinference/web/ui/node_modules/.cache/babel-loader/822586ed1077201b64b954f12f25e3f9b45678c1acbabe53d8af3ca82ca71f33.json +0 -1
  354. xinference/web/ui/node_modules/.cache/babel-loader/8d33354bd2100c8602afc3341f131a88cc36aaeecd5a4b365ed038514708e350.json +0 -1
  355. xinference/web/ui/node_modules/.cache/babel-loader/9375a35b05d56989b2755bf72161fa707c92f28569d33765a75f91a568fda6e9.json +0 -1
  356. xinference/web/ui/node_modules/.cache/babel-loader/a158a9ffa0c9b169aee53dd4a0c44501a596755b4e4f6ede7746d65a72e2a71f.json +0 -1
  357. xinference/web/ui/node_modules/.cache/babel-loader/bd6ad8159341315a1764c397621a560809f7eb7219ab5174c801fca7e969d943.json +0 -1
  358. xinference/web/ui/node_modules/.cache/babel-loader/c7bf40bab396765f67d0fed627ed3665890608b2d0edaa3e8cb7cfc96310db45.json +0 -1
  359. xinference/web/ui/node_modules/.cache/babel-loader/d6c643278a0b28320e6f33a60f5fb64c053997cbdc39a60e53ccc574688ade9e.json +0 -1
  360. xinference/web/ui/node_modules/.cache/babel-loader/e42b72d4cc1ea412ebecbb8d040dc6c6bfee462c33903c2f1f3facb602ad742e.json +0 -1
  361. xinference/web/ui/node_modules/.cache/babel-loader/e64b7e8cedcf43d4c95deba60ec1341855c887705805bb62431693118b870c69.json +0 -1
  362. xinference/web/ui/node_modules/.cache/babel-loader/f5039ddbeb815c51491a1989532006b96fc3ae49c6c60e3c097f875b4ae915ae.json +0 -1
  363. xinference/web/ui/node_modules/.cache/babel-loader/f72f011744c4649fabddca6f7a9327861ac0a315a89b1a2e62a39774e7863845.json +0 -1
  364. xinference/web/ui/node_modules/.cache/babel-loader/feabb04b4aa507102da0a64398a40818e878fd1df9b75dda8461b3e1e7ff3f11.json +0 -1
  365. /xinference/thirdparty/{cosyvoice/bin → f5_tts}/__init__.py +0 -0
  366. /xinference/thirdparty/{cosyvoice/flow → melo}/__init__.py +0 -0
  367. /xinference/thirdparty/{cosyvoice/hifigan → melo/text/english_utils}/__init__.py +0 -0
  368. /xinference/thirdparty/{cosyvoice/llm → melo/text/es_phonemizer}/__init__.py +0 -0
  369. /xinference/thirdparty/{fish_speech/fish_speech/configs → melo/text/fr_phonemizer}/__init__.py +0 -0
  370. /xinference/web/ui/build/static/js/{main.2f269bb3.js.LICENSE.txt → main.b0936c54.js.LICENSE.txt} +0 -0
  371. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/LICENSE +0 -0
  372. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/entry_points.txt +0 -0
  373. {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,851 @@
1
+ # ruff: noqa: E402
2
+ # Above allows ruff to ignore E402: module level import not at top of file
3
+
4
+ import re
5
+ import tempfile
6
+ from collections import OrderedDict
7
+ from importlib.resources import files
8
+
9
+ import click
10
+ import gradio as gr
11
+ import numpy as np
12
+ import soundfile as sf
13
+ import torchaudio
14
+ from cached_path import cached_path
15
+ from transformers import AutoModelForCausalLM, AutoTokenizer
16
+
17
+ try:
18
+ import spaces
19
+
20
+ USING_SPACES = True
21
+ except ImportError:
22
+ USING_SPACES = False
23
+
24
+
25
+ def gpu_decorator(func):
26
+ if USING_SPACES:
27
+ return spaces.GPU(func)
28
+ else:
29
+ return func
30
+
31
+
32
+ from f5_tts.model import DiT, UNetT
33
+ from f5_tts.infer.utils_infer import (
34
+ load_vocoder,
35
+ load_model,
36
+ preprocess_ref_audio_text,
37
+ infer_process,
38
+ remove_silence_for_generated_wav,
39
+ save_spectrogram,
40
+ )
41
+
42
+
43
+ DEFAULT_TTS_MODEL = "F5-TTS"
44
+ tts_model_choice = DEFAULT_TTS_MODEL
45
+
46
+
47
+ # load models
48
+
49
+ vocoder = load_vocoder()
50
+
51
+
52
+ def load_f5tts(ckpt_path=str(cached_path("hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors"))):
53
+ F5TTS_model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)
54
+ return load_model(DiT, F5TTS_model_cfg, ckpt_path)
55
+
56
+
57
+ def load_e2tts(ckpt_path=str(cached_path("hf://SWivid/E2-TTS/E2TTS_Base/model_1200000.safetensors"))):
58
+ E2TTS_model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)
59
+ return load_model(UNetT, E2TTS_model_cfg, ckpt_path)
60
+
61
+
62
+ def load_custom(ckpt_path: str, vocab_path="", model_cfg=None):
63
+ ckpt_path, vocab_path = ckpt_path.strip(), vocab_path.strip()
64
+ if ckpt_path.startswith("hf://"):
65
+ ckpt_path = str(cached_path(ckpt_path))
66
+ if vocab_path.startswith("hf://"):
67
+ vocab_path = str(cached_path(vocab_path))
68
+ if model_cfg is None:
69
+ model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)
70
+ return load_model(DiT, model_cfg, ckpt_path, vocab_file=vocab_path)
71
+
72
+
73
+ F5TTS_ema_model = load_f5tts()
74
+ E2TTS_ema_model = load_e2tts() if USING_SPACES else None
75
+ custom_ema_model, pre_custom_path = None, ""
76
+
77
+ chat_model_state = None
78
+ chat_tokenizer_state = None
79
+
80
+
81
+ @gpu_decorator
82
+ def generate_response(messages, model, tokenizer):
83
+ """Generate response using Qwen"""
84
+ text = tokenizer.apply_chat_template(
85
+ messages,
86
+ tokenize=False,
87
+ add_generation_prompt=True,
88
+ )
89
+
90
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
91
+ generated_ids = model.generate(
92
+ **model_inputs,
93
+ max_new_tokens=512,
94
+ temperature=0.7,
95
+ top_p=0.95,
96
+ )
97
+
98
+ generated_ids = [
99
+ output_ids[len(input_ids) :] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
100
+ ]
101
+ return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
102
+
103
+
104
+ @gpu_decorator
105
+ def infer(
106
+ ref_audio_orig, ref_text, gen_text, model, remove_silence, cross_fade_duration=0.15, speed=1, show_info=gr.Info
107
+ ):
108
+ ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, ref_text, show_info=show_info)
109
+
110
+ if model == "F5-TTS":
111
+ ema_model = F5TTS_ema_model
112
+ elif model == "E2-TTS":
113
+ global E2TTS_ema_model
114
+ if E2TTS_ema_model is None:
115
+ show_info("Loading E2-TTS model...")
116
+ E2TTS_ema_model = load_e2tts()
117
+ ema_model = E2TTS_ema_model
118
+ elif isinstance(model, list) and model[0] == "Custom":
119
+ assert not USING_SPACES, "Only official checkpoints allowed in Spaces."
120
+ global custom_ema_model, pre_custom_path
121
+ if pre_custom_path != model[1]:
122
+ show_info("Loading Custom TTS model...")
123
+ custom_ema_model = load_custom(model[1], vocab_path=model[2])
124
+ pre_custom_path = model[1]
125
+ ema_model = custom_ema_model
126
+
127
+ final_wave, final_sample_rate, combined_spectrogram = infer_process(
128
+ ref_audio,
129
+ ref_text,
130
+ gen_text,
131
+ ema_model,
132
+ vocoder,
133
+ cross_fade_duration=cross_fade_duration,
134
+ speed=speed,
135
+ show_info=show_info,
136
+ progress=gr.Progress(),
137
+ )
138
+
139
+ # Remove silence
140
+ if remove_silence:
141
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
142
+ sf.write(f.name, final_wave, final_sample_rate)
143
+ remove_silence_for_generated_wav(f.name)
144
+ final_wave, _ = torchaudio.load(f.name)
145
+ final_wave = final_wave.squeeze().cpu().numpy()
146
+
147
+ # Save the spectrogram
148
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_spectrogram:
149
+ spectrogram_path = tmp_spectrogram.name
150
+ save_spectrogram(combined_spectrogram, spectrogram_path)
151
+
152
+ return (final_sample_rate, final_wave), spectrogram_path, ref_text
153
+
154
+
155
+ with gr.Blocks() as app_credits:
156
+ gr.Markdown("""
157
+ # Credits
158
+
159
+ * [mrfakename](https://github.com/fakerybakery) for the original [online demo](https://huggingface.co/spaces/mrfakename/E2-F5-TTS)
160
+ * [RootingInLoad](https://github.com/RootingInLoad) for initial chunk generation and podcast app exploration
161
+ * [jpgallegoar](https://github.com/jpgallegoar) for multiple speech-type generation & voice chat
162
+ """)
163
+ with gr.Blocks() as app_tts:
164
+ gr.Markdown("# Batched TTS")
165
+ ref_audio_input = gr.Audio(label="Reference Audio", type="filepath")
166
+ gen_text_input = gr.Textbox(label="Text to Generate", lines=10)
167
+ generate_btn = gr.Button("Synthesize", variant="primary")
168
+ with gr.Accordion("Advanced Settings", open=False):
169
+ ref_text_input = gr.Textbox(
170
+ label="Reference Text",
171
+ info="Leave blank to automatically transcribe the reference audio. If you enter text it will override automatic transcription.",
172
+ lines=2,
173
+ )
174
+ remove_silence = gr.Checkbox(
175
+ label="Remove Silences",
176
+ info="The model tends to produce silences, especially on longer audio. We can manually remove silences if needed. Note that this is an experimental feature and may produce strange results. This will also increase generation time.",
177
+ value=False,
178
+ )
179
+ speed_slider = gr.Slider(
180
+ label="Speed",
181
+ minimum=0.3,
182
+ maximum=2.0,
183
+ value=1.0,
184
+ step=0.1,
185
+ info="Adjust the speed of the audio.",
186
+ )
187
+ cross_fade_duration_slider = gr.Slider(
188
+ label="Cross-Fade Duration (s)",
189
+ minimum=0.0,
190
+ maximum=1.0,
191
+ value=0.15,
192
+ step=0.01,
193
+ info="Set the duration of the cross-fade between audio clips.",
194
+ )
195
+
196
+ audio_output = gr.Audio(label="Synthesized Audio")
197
+ spectrogram_output = gr.Image(label="Spectrogram")
198
+
199
+ @gpu_decorator
200
+ def basic_tts(
201
+ ref_audio_input,
202
+ ref_text_input,
203
+ gen_text_input,
204
+ remove_silence,
205
+ cross_fade_duration_slider,
206
+ speed_slider,
207
+ ):
208
+ audio_out, spectrogram_path, ref_text_out = infer(
209
+ ref_audio_input,
210
+ ref_text_input,
211
+ gen_text_input,
212
+ tts_model_choice,
213
+ remove_silence,
214
+ cross_fade_duration_slider,
215
+ speed_slider,
216
+ )
217
+ return audio_out, spectrogram_path, gr.update(value=ref_text_out)
218
+
219
+ generate_btn.click(
220
+ basic_tts,
221
+ inputs=[
222
+ ref_audio_input,
223
+ ref_text_input,
224
+ gen_text_input,
225
+ remove_silence,
226
+ cross_fade_duration_slider,
227
+ speed_slider,
228
+ ],
229
+ outputs=[audio_output, spectrogram_output, ref_text_input],
230
+ )
231
+
232
+
233
+ def parse_speechtypes_text(gen_text):
234
+ # Pattern to find {speechtype}
235
+ pattern = r"\{(.*?)\}"
236
+
237
+ # Split the text by the pattern
238
+ tokens = re.split(pattern, gen_text)
239
+
240
+ segments = []
241
+
242
+ current_style = "Regular"
243
+
244
+ for i in range(len(tokens)):
245
+ if i % 2 == 0:
246
+ # This is text
247
+ text = tokens[i].strip()
248
+ if text:
249
+ segments.append({"style": current_style, "text": text})
250
+ else:
251
+ # This is style
252
+ style = tokens[i].strip()
253
+ current_style = style
254
+
255
+ return segments
256
+
257
+
258
+ with gr.Blocks() as app_multistyle:
259
+ # New section for multistyle generation
260
+ gr.Markdown(
261
+ """
262
+ # Multiple Speech-Type Generation
263
+
264
+ This section allows you to generate multiple speech types or multiple people's voices. Enter your text in the format shown below, and the system will generate speech using the appropriate type. If unspecified, the model will use the regular speech type. The current speech type will be used until the next speech type is specified.
265
+ """
266
+ )
267
+
268
+ with gr.Row():
269
+ gr.Markdown(
270
+ """
271
+ **Example Input:**
272
+ {Regular} Hello, I'd like to order a sandwich please.
273
+ {Surprised} What do you mean you're out of bread?
274
+ {Sad} I really wanted a sandwich though...
275
+ {Angry} You know what, darn you and your little shop!
276
+ {Whisper} I'll just go back home and cry now.
277
+ {Shouting} Why me?!
278
+ """
279
+ )
280
+
281
+ gr.Markdown(
282
+ """
283
+ **Example Input 2:**
284
+ {Speaker1_Happy} Hello, I'd like to order a sandwich please.
285
+ {Speaker2_Regular} Sorry, we're out of bread.
286
+ {Speaker1_Sad} I really wanted a sandwich though...
287
+ {Speaker2_Whisper} I'll give you the last one I was hiding.
288
+ """
289
+ )
290
+
291
+ gr.Markdown(
292
+ "Upload different audio clips for each speech type. The first speech type is mandatory. You can add additional speech types by clicking the 'Add Speech Type' button."
293
+ )
294
+
295
+ # Regular speech type (mandatory)
296
+ with gr.Row():
297
+ with gr.Column():
298
+ regular_name = gr.Textbox(value="Regular", label="Speech Type Name")
299
+ regular_insert = gr.Button("Insert Label", variant="secondary")
300
+ regular_audio = gr.Audio(label="Regular Reference Audio", type="filepath")
301
+ regular_ref_text = gr.Textbox(label="Reference Text (Regular)", lines=2)
302
+
303
+ # Regular speech type (max 100)
304
+ max_speech_types = 100
305
+ speech_type_rows = [] # 99
306
+ speech_type_names = [regular_name] # 100
307
+ speech_type_audios = [regular_audio] # 100
308
+ speech_type_ref_texts = [regular_ref_text] # 100
309
+ speech_type_delete_btns = [] # 99
310
+ speech_type_insert_btns = [regular_insert] # 100
311
+
312
+ # Additional speech types (99 more)
313
+ for i in range(max_speech_types - 1):
314
+ with gr.Row(visible=False) as row:
315
+ with gr.Column():
316
+ name_input = gr.Textbox(label="Speech Type Name")
317
+ delete_btn = gr.Button("Delete Type", variant="secondary")
318
+ insert_btn = gr.Button("Insert Label", variant="secondary")
319
+ audio_input = gr.Audio(label="Reference Audio", type="filepath")
320
+ ref_text_input = gr.Textbox(label="Reference Text", lines=2)
321
+ speech_type_rows.append(row)
322
+ speech_type_names.append(name_input)
323
+ speech_type_audios.append(audio_input)
324
+ speech_type_ref_texts.append(ref_text_input)
325
+ speech_type_delete_btns.append(delete_btn)
326
+ speech_type_insert_btns.append(insert_btn)
327
+
328
+ # Button to add speech type
329
+ add_speech_type_btn = gr.Button("Add Speech Type")
330
+
331
+ # Keep track of current number of speech types
332
+ speech_type_count = gr.State(value=1)
333
+
334
+ # Function to add a speech type
335
+ def add_speech_type_fn(speech_type_count):
336
+ if speech_type_count < max_speech_types:
337
+ speech_type_count += 1
338
+ # Prepare updates for the rows
339
+ row_updates = []
340
+ for i in range(1, max_speech_types):
341
+ if i < speech_type_count:
342
+ row_updates.append(gr.update(visible=True))
343
+ else:
344
+ row_updates.append(gr.update())
345
+ else:
346
+ # Optionally, show a warning
347
+ row_updates = [gr.update() for _ in range(1, max_speech_types)]
348
+ return [speech_type_count] + row_updates
349
+
350
+ add_speech_type_btn.click(
351
+ add_speech_type_fn, inputs=speech_type_count, outputs=[speech_type_count] + speech_type_rows
352
+ )
353
+
354
+ # Function to delete a speech type
355
+ def make_delete_speech_type_fn(index):
356
+ def delete_speech_type_fn(speech_type_count):
357
+ # Prepare updates
358
+ row_updates = []
359
+
360
+ for i in range(1, max_speech_types):
361
+ if i == index:
362
+ row_updates.append(gr.update(visible=False))
363
+ else:
364
+ row_updates.append(gr.update())
365
+
366
+ speech_type_count = max(1, speech_type_count)
367
+
368
+ return [speech_type_count] + row_updates
369
+
370
+ return delete_speech_type_fn
371
+
372
+ # Update delete button clicks
373
+ for i, delete_btn in enumerate(speech_type_delete_btns):
374
+ delete_fn = make_delete_speech_type_fn(i)
375
+ delete_btn.click(delete_fn, inputs=speech_type_count, outputs=[speech_type_count] + speech_type_rows)
376
+
377
+ # Text input for the prompt
378
+ gen_text_input_multistyle = gr.Textbox(
379
+ label="Text to Generate",
380
+ lines=10,
381
+ placeholder="Enter the script with speaker names (or emotion types) at the start of each block, e.g.:\n\n{Regular} Hello, I'd like to order a sandwich please.\n{Surprised} What do you mean you're out of bread?\n{Sad} I really wanted a sandwich though...\n{Angry} You know what, darn you and your little shop!\n{Whisper} I'll just go back home and cry now.\n{Shouting} Why me?!",
382
+ )
383
+
384
+ def make_insert_speech_type_fn(index):
385
+ def insert_speech_type_fn(current_text, speech_type_name):
386
+ current_text = current_text or ""
387
+ speech_type_name = speech_type_name or "None"
388
+ updated_text = current_text + f"{{{speech_type_name}}} "
389
+ return gr.update(value=updated_text)
390
+
391
+ return insert_speech_type_fn
392
+
393
+ for i, insert_btn in enumerate(speech_type_insert_btns):
394
+ insert_fn = make_insert_speech_type_fn(i)
395
+ insert_btn.click(
396
+ insert_fn,
397
+ inputs=[gen_text_input_multistyle, speech_type_names[i]],
398
+ outputs=gen_text_input_multistyle,
399
+ )
400
+
401
+ with gr.Accordion("Advanced Settings", open=False):
402
+ remove_silence_multistyle = gr.Checkbox(
403
+ label="Remove Silences",
404
+ value=True,
405
+ )
406
+
407
+ # Generate button
408
+ generate_multistyle_btn = gr.Button("Generate Multi-Style Speech", variant="primary")
409
+
410
+ # Output audio
411
+ audio_output_multistyle = gr.Audio(label="Synthesized Audio")
412
+
413
+ @gpu_decorator
414
+ def generate_multistyle_speech(
415
+ gen_text,
416
+ *args,
417
+ ):
418
+ speech_type_names_list = args[:max_speech_types]
419
+ speech_type_audios_list = args[max_speech_types : 2 * max_speech_types]
420
+ speech_type_ref_texts_list = args[2 * max_speech_types : 3 * max_speech_types]
421
+ remove_silence = args[3 * max_speech_types]
422
+ # Collect the speech types and their audios into a dict
423
+ speech_types = OrderedDict()
424
+
425
+ ref_text_idx = 0
426
+ for name_input, audio_input, ref_text_input in zip(
427
+ speech_type_names_list, speech_type_audios_list, speech_type_ref_texts_list
428
+ ):
429
+ if name_input and audio_input:
430
+ speech_types[name_input] = {"audio": audio_input, "ref_text": ref_text_input}
431
+ else:
432
+ speech_types[f"@{ref_text_idx}@"] = {"audio": "", "ref_text": ""}
433
+ ref_text_idx += 1
434
+
435
+ # Parse the gen_text into segments
436
+ segments = parse_speechtypes_text(gen_text)
437
+
438
+ # For each segment, generate speech
439
+ generated_audio_segments = []
440
+ current_style = "Regular"
441
+
442
+ for segment in segments:
443
+ style = segment["style"]
444
+ text = segment["text"]
445
+
446
+ if style in speech_types:
447
+ current_style = style
448
+ else:
449
+ # If style not available, default to Regular
450
+ current_style = "Regular"
451
+
452
+ ref_audio = speech_types[current_style]["audio"]
453
+ ref_text = speech_types[current_style].get("ref_text", "")
454
+
455
+ # Generate speech for this segment
456
+ audio_out, _, ref_text_out = infer(
457
+ ref_audio, ref_text, text, tts_model_choice, remove_silence, 0, show_info=print
458
+ ) # show_info=print no pull to top when generating
459
+ sr, audio_data = audio_out
460
+
461
+ generated_audio_segments.append(audio_data)
462
+ speech_types[current_style]["ref_text"] = ref_text_out
463
+
464
+ # Concatenate all audio segments
465
+ if generated_audio_segments:
466
+ final_audio_data = np.concatenate(generated_audio_segments)
467
+ return [(sr, final_audio_data)] + [
468
+ gr.update(value=speech_types[style]["ref_text"]) for style in speech_types
469
+ ]
470
+ else:
471
+ gr.Warning("No audio generated.")
472
+ return [None] + [gr.update(value=speech_types[style]["ref_text"]) for style in speech_types]
473
+
474
+ generate_multistyle_btn.click(
475
+ generate_multistyle_speech,
476
+ inputs=[
477
+ gen_text_input_multistyle,
478
+ ]
479
+ + speech_type_names
480
+ + speech_type_audios
481
+ + speech_type_ref_texts
482
+ + [
483
+ remove_silence_multistyle,
484
+ ],
485
+ outputs=[audio_output_multistyle] + speech_type_ref_texts,
486
+ )
487
+
488
+ # Validation function to disable Generate button if speech types are missing
489
+ def validate_speech_types(gen_text, regular_name, *args):
490
+ speech_type_names_list = args[:max_speech_types]
491
+
492
+ # Collect the speech types names
493
+ speech_types_available = set()
494
+ if regular_name:
495
+ speech_types_available.add(regular_name)
496
+ for name_input in speech_type_names_list:
497
+ if name_input:
498
+ speech_types_available.add(name_input)
499
+
500
+ # Parse the gen_text to get the speech types used
501
+ segments = parse_speechtypes_text(gen_text)
502
+ speech_types_in_text = set(segment["style"] for segment in segments)
503
+
504
+ # Check if all speech types in text are available
505
+ missing_speech_types = speech_types_in_text - speech_types_available
506
+
507
+ if missing_speech_types:
508
+ # Disable the generate button
509
+ return gr.update(interactive=False)
510
+ else:
511
+ # Enable the generate button
512
+ return gr.update(interactive=True)
513
+
514
+ gen_text_input_multistyle.change(
515
+ validate_speech_types,
516
+ inputs=[gen_text_input_multistyle, regular_name] + speech_type_names,
517
+ outputs=generate_multistyle_btn,
518
+ )
519
+
520
+
521
+ with gr.Blocks() as app_chat:
522
+ gr.Markdown(
523
+ """
524
+ # Voice Chat
525
+ Have a conversation with an AI using your reference voice!
526
+ 1. Upload a reference audio clip and optionally its transcript.
527
+ 2. Load the chat model.
528
+ 3. Record your message through your microphone.
529
+ 4. The AI will respond using the reference voice.
530
+ """
531
+ )
532
+
533
+ if not USING_SPACES:
534
+ load_chat_model_btn = gr.Button("Load Chat Model", variant="primary")
535
+
536
+ chat_interface_container = gr.Column(visible=False)
537
+
538
+ @gpu_decorator
539
+ def load_chat_model():
540
+ global chat_model_state, chat_tokenizer_state
541
+ if chat_model_state is None:
542
+ show_info = gr.Info
543
+ show_info("Loading chat model...")
544
+ model_name = "Qwen/Qwen2.5-3B-Instruct"
545
+ chat_model_state = AutoModelForCausalLM.from_pretrained(
546
+ model_name, torch_dtype="auto", device_map="auto"
547
+ )
548
+ chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
549
+ show_info("Chat model loaded.")
550
+
551
+ return gr.update(visible=False), gr.update(visible=True)
552
+
553
+ load_chat_model_btn.click(load_chat_model, outputs=[load_chat_model_btn, chat_interface_container])
554
+
555
+ else:
556
+ chat_interface_container = gr.Column()
557
+
558
+ if chat_model_state is None:
559
+ model_name = "Qwen/Qwen2.5-3B-Instruct"
560
+ chat_model_state = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
561
+ chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
562
+
563
+ with chat_interface_container:
564
+ with gr.Row():
565
+ with gr.Column():
566
+ ref_audio_chat = gr.Audio(label="Reference Audio", type="filepath")
567
+ with gr.Column():
568
+ with gr.Accordion("Advanced Settings", open=False):
569
+ remove_silence_chat = gr.Checkbox(
570
+ label="Remove Silences",
571
+ value=True,
572
+ )
573
+ ref_text_chat = gr.Textbox(
574
+ label="Reference Text",
575
+ info="Optional: Leave blank to auto-transcribe",
576
+ lines=2,
577
+ )
578
+ system_prompt_chat = gr.Textbox(
579
+ label="System Prompt",
580
+ value="You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
581
+ lines=2,
582
+ )
583
+
584
+ chatbot_interface = gr.Chatbot(label="Conversation")
585
+
586
+ with gr.Row():
587
+ with gr.Column():
588
+ audio_input_chat = gr.Microphone(
589
+ label="Speak your message",
590
+ type="filepath",
591
+ )
592
+ audio_output_chat = gr.Audio(autoplay=True)
593
+ with gr.Column():
594
+ text_input_chat = gr.Textbox(
595
+ label="Type your message",
596
+ lines=1,
597
+ )
598
+ send_btn_chat = gr.Button("Send Message")
599
+ clear_btn_chat = gr.Button("Clear Conversation")
600
+
601
+ conversation_state = gr.State(
602
+ value=[
603
+ {
604
+ "role": "system",
605
+ "content": "You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
606
+ }
607
+ ]
608
+ )
609
+
610
+ # Modify process_audio_input to use model and tokenizer from state
611
+ @gpu_decorator
612
+ def process_audio_input(audio_path, text, history, conv_state):
613
+ """Handle audio or text input from user"""
614
+
615
+ if not audio_path and not text.strip():
616
+ return history, conv_state, ""
617
+
618
+ if audio_path:
619
+ text = preprocess_ref_audio_text(audio_path, text)[1]
620
+
621
+ if not text.strip():
622
+ return history, conv_state, ""
623
+
624
+ conv_state.append({"role": "user", "content": text})
625
+ history.append((text, None))
626
+
627
+ response = generate_response(conv_state, chat_model_state, chat_tokenizer_state)
628
+
629
+ conv_state.append({"role": "assistant", "content": response})
630
+ history[-1] = (text, response)
631
+
632
+ return history, conv_state, ""
633
+
634
+ @gpu_decorator
635
+ def generate_audio_response(history, ref_audio, ref_text, remove_silence):
636
+ """Generate TTS audio for AI response"""
637
+ if not history or not ref_audio:
638
+ return None
639
+
640
+ last_user_message, last_ai_response = history[-1]
641
+ if not last_ai_response:
642
+ return None
643
+
644
+ audio_result, _, ref_text_out = infer(
645
+ ref_audio,
646
+ ref_text,
647
+ last_ai_response,
648
+ tts_model_choice,
649
+ remove_silence,
650
+ cross_fade_duration=0.15,
651
+ speed=1.0,
652
+ show_info=print, # show_info=print no pull to top when generating
653
+ )
654
+ return audio_result, gr.update(value=ref_text_out)
655
+
656
+ def clear_conversation():
657
+ """Reset the conversation"""
658
+ return [], [
659
+ {
660
+ "role": "system",
661
+ "content": "You are not an AI assistant, you are whoever the user says you are. You must stay in character. Keep your responses concise since they will be spoken out loud.",
662
+ }
663
+ ]
664
+
665
+ def update_system_prompt(new_prompt):
666
+ """Update the system prompt and reset the conversation"""
667
+ new_conv_state = [{"role": "system", "content": new_prompt}]
668
+ return [], new_conv_state
669
+
670
+ # Handle audio input
671
+ audio_input_chat.stop_recording(
672
+ process_audio_input,
673
+ inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
674
+ outputs=[chatbot_interface, conversation_state],
675
+ ).then(
676
+ generate_audio_response,
677
+ inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
678
+ outputs=[audio_output_chat, ref_text_chat],
679
+ ).then(
680
+ lambda: None,
681
+ None,
682
+ audio_input_chat,
683
+ )
684
+
685
+ # Handle text input
686
+ text_input_chat.submit(
687
+ process_audio_input,
688
+ inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
689
+ outputs=[chatbot_interface, conversation_state],
690
+ ).then(
691
+ generate_audio_response,
692
+ inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
693
+ outputs=[audio_output_chat, ref_text_chat],
694
+ ).then(
695
+ lambda: None,
696
+ None,
697
+ text_input_chat,
698
+ )
699
+
700
+ # Handle send button
701
+ send_btn_chat.click(
702
+ process_audio_input,
703
+ inputs=[audio_input_chat, text_input_chat, chatbot_interface, conversation_state],
704
+ outputs=[chatbot_interface, conversation_state],
705
+ ).then(
706
+ generate_audio_response,
707
+ inputs=[chatbot_interface, ref_audio_chat, ref_text_chat, remove_silence_chat],
708
+ outputs=[audio_output_chat, ref_text_chat],
709
+ ).then(
710
+ lambda: None,
711
+ None,
712
+ text_input_chat,
713
+ )
714
+
715
+ # Handle clear button
716
+ clear_btn_chat.click(
717
+ clear_conversation,
718
+ outputs=[chatbot_interface, conversation_state],
719
+ )
720
+
721
+ # Handle system prompt change and reset conversation
722
+ system_prompt_chat.change(
723
+ update_system_prompt,
724
+ inputs=system_prompt_chat,
725
+ outputs=[chatbot_interface, conversation_state],
726
+ )
727
+
728
+
729
+ with gr.Blocks() as app:
730
+ gr.Markdown(
731
+ """
732
+ # E2/F5 TTS
733
+
734
+ This is a local web UI for F5 TTS with advanced batch processing support. This app supports the following TTS models:
735
+
736
+ * [F5-TTS](https://arxiv.org/abs/2410.06885) (A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching)
737
+ * [E2 TTS](https://arxiv.org/abs/2406.18009) (Embarrassingly Easy Fully Non-Autoregressive Zero-Shot TTS)
738
+
739
+ The checkpoints currently support English and Chinese.
740
+
741
+ If you're having issues, try converting your reference audio to WAV or MP3, clipping it to 15s with ✂ in the bottom right corner (otherwise might have non-optimal auto-trimmed result).
742
+
743
+ **NOTE: Reference text will be automatically transcribed with Whisper if not provided. For best results, keep your reference clips short (<15s). Ensure the audio is fully uploaded before generating.**
744
+ """
745
+ )
746
+
747
+ last_used_custom = files("f5_tts").joinpath("infer/.cache/last_used_custom.txt")
748
+
749
+ def load_last_used_custom():
750
+ try:
751
+ with open(last_used_custom, "r") as f:
752
+ return f.read().split(",")
753
+ except FileNotFoundError:
754
+ last_used_custom.parent.mkdir(parents=True, exist_ok=True)
755
+ return [
756
+ "hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors",
757
+ "hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt",
758
+ ]
759
+
760
+ def switch_tts_model(new_choice):
761
+ global tts_model_choice
762
+ if new_choice == "Custom": # override in case webpage is refreshed
763
+ custom_ckpt_path, custom_vocab_path = load_last_used_custom()
764
+ tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path]
765
+ return gr.update(visible=True, value=custom_ckpt_path), gr.update(visible=True, value=custom_vocab_path)
766
+ else:
767
+ tts_model_choice = new_choice
768
+ return gr.update(visible=False), gr.update(visible=False)
769
+
770
+ def set_custom_model(custom_ckpt_path, custom_vocab_path):
771
+ global tts_model_choice
772
+ tts_model_choice = ["Custom", custom_ckpt_path, custom_vocab_path]
773
+ with open(last_used_custom, "w") as f:
774
+ f.write(f"{custom_ckpt_path},{custom_vocab_path}")
775
+
776
+ with gr.Row():
777
+ if not USING_SPACES:
778
+ choose_tts_model = gr.Radio(
779
+ choices=[DEFAULT_TTS_MODEL, "E2-TTS", "Custom"], label="Choose TTS Model", value=DEFAULT_TTS_MODEL
780
+ )
781
+ else:
782
+ choose_tts_model = gr.Radio(
783
+ choices=[DEFAULT_TTS_MODEL, "E2-TTS"], label="Choose TTS Model", value=DEFAULT_TTS_MODEL
784
+ )
785
+ custom_ckpt_path = gr.Dropdown(
786
+ choices=["hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors"],
787
+ value=load_last_used_custom()[0],
788
+ allow_custom_value=True,
789
+ label="MODEL CKPT: local_path | hf://user_id/repo_id/model_ckpt",
790
+ visible=False,
791
+ )
792
+ custom_vocab_path = gr.Dropdown(
793
+ choices=["hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt"],
794
+ value=load_last_used_custom()[1],
795
+ allow_custom_value=True,
796
+ label="VOCAB FILE: local_path | hf://user_id/repo_id/vocab_file",
797
+ visible=False,
798
+ )
799
+
800
+ choose_tts_model.change(
801
+ switch_tts_model,
802
+ inputs=[choose_tts_model],
803
+ outputs=[custom_ckpt_path, custom_vocab_path],
804
+ show_progress="hidden",
805
+ )
806
+ custom_ckpt_path.change(
807
+ set_custom_model,
808
+ inputs=[custom_ckpt_path, custom_vocab_path],
809
+ show_progress="hidden",
810
+ )
811
+ custom_vocab_path.change(
812
+ set_custom_model,
813
+ inputs=[custom_ckpt_path, custom_vocab_path],
814
+ show_progress="hidden",
815
+ )
816
+
817
+ gr.TabbedInterface(
818
+ [app_tts, app_multistyle, app_chat, app_credits],
819
+ ["Basic-TTS", "Multi-Speech", "Voice-Chat", "Credits"],
820
+ )
821
+
822
+
823
+ @click.command()
824
+ @click.option("--port", "-p", default=None, type=int, help="Port to run the app on")
825
+ @click.option("--host", "-H", default=None, help="Host to run the app on")
826
+ @click.option(
827
+ "--share",
828
+ "-s",
829
+ default=False,
830
+ is_flag=True,
831
+ help="Share the app via Gradio share link",
832
+ )
833
+ @click.option("--api", "-a", default=True, is_flag=True, help="Allow API access")
834
+ @click.option(
835
+ "--root_path",
836
+ "-r",
837
+ default=None,
838
+ type=str,
839
+ help='The root path (or "mount point") of the application, if it\'s not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application, e.g. set "/myapp" or full URL for application served at "https://example.com/myapp".',
840
+ )
841
+ def main(port, host, share, api, root_path):
842
+ global app
843
+ print("Starting app...")
844
+ app.queue(api_open=api).launch(server_name=host, server_port=port, share=share, show_api=api, root_path=root_path)
845
+
846
+
847
+ if __name__ == "__main__":
848
+ if not USING_SPACES:
849
+ main()
850
+ else:
851
+ app.queue().launch()