xinference 1.0.1__py3-none-any.whl → 1.1.0__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 (87) hide show
  1. xinference/_version.py +3 -3
  2. xinference/api/restful_api.py +5 -5
  3. xinference/core/model.py +6 -1
  4. xinference/deploy/cmdline.py +3 -1
  5. xinference/deploy/test/test_cmdline.py +56 -0
  6. xinference/isolation.py +24 -0
  7. xinference/model/audio/core.py +5 -0
  8. xinference/model/audio/f5tts.py +195 -0
  9. xinference/model/audio/fish_speech.py +2 -1
  10. xinference/model/audio/model_spec.json +8 -0
  11. xinference/model/audio/model_spec_modelscope.json +9 -0
  12. xinference/model/embedding/core.py +203 -142
  13. xinference/model/embedding/model_spec.json +7 -0
  14. xinference/model/embedding/model_spec_modelscope.json +8 -0
  15. xinference/model/llm/__init__.py +2 -2
  16. xinference/model/llm/llm_family.json +172 -53
  17. xinference/model/llm/llm_family_modelscope.json +118 -20
  18. xinference/model/llm/mlx/core.py +230 -49
  19. xinference/model/llm/sglang/core.py +1 -0
  20. xinference/model/llm/transformers/chatglm.py +9 -5
  21. xinference/model/llm/transformers/utils.py +16 -8
  22. xinference/model/llm/utils.py +4 -1
  23. xinference/model/llm/vllm/core.py +5 -0
  24. xinference/thirdparty/f5_tts/__init__.py +0 -0
  25. xinference/thirdparty/f5_tts/api.py +166 -0
  26. xinference/thirdparty/f5_tts/configs/E2TTS_Base_train.yaml +44 -0
  27. xinference/thirdparty/f5_tts/configs/E2TTS_Small_train.yaml +44 -0
  28. xinference/thirdparty/f5_tts/configs/F5TTS_Base_train.yaml +46 -0
  29. xinference/thirdparty/f5_tts/configs/F5TTS_Small_train.yaml +46 -0
  30. xinference/thirdparty/f5_tts/eval/README.md +49 -0
  31. xinference/thirdparty/f5_tts/eval/ecapa_tdnn.py +330 -0
  32. xinference/thirdparty/f5_tts/eval/eval_infer_batch.py +207 -0
  33. xinference/thirdparty/f5_tts/eval/eval_infer_batch.sh +13 -0
  34. xinference/thirdparty/f5_tts/eval/eval_librispeech_test_clean.py +84 -0
  35. xinference/thirdparty/f5_tts/eval/eval_seedtts_testset.py +84 -0
  36. xinference/thirdparty/f5_tts/eval/utils_eval.py +405 -0
  37. xinference/thirdparty/f5_tts/infer/README.md +191 -0
  38. xinference/thirdparty/f5_tts/infer/SHARED.md +74 -0
  39. xinference/thirdparty/f5_tts/infer/examples/basic/basic.toml +11 -0
  40. xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_en.wav +0 -0
  41. xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_zh.wav +0 -0
  42. xinference/thirdparty/f5_tts/infer/examples/multi/country.flac +0 -0
  43. xinference/thirdparty/f5_tts/infer/examples/multi/main.flac +0 -0
  44. xinference/thirdparty/f5_tts/infer/examples/multi/story.toml +19 -0
  45. xinference/thirdparty/f5_tts/infer/examples/multi/story.txt +1 -0
  46. xinference/thirdparty/f5_tts/infer/examples/multi/town.flac +0 -0
  47. xinference/thirdparty/f5_tts/infer/examples/vocab.txt +2545 -0
  48. xinference/thirdparty/f5_tts/infer/infer_cli.py +226 -0
  49. xinference/thirdparty/f5_tts/infer/infer_gradio.py +851 -0
  50. xinference/thirdparty/f5_tts/infer/speech_edit.py +193 -0
  51. xinference/thirdparty/f5_tts/infer/utils_infer.py +538 -0
  52. xinference/thirdparty/f5_tts/model/__init__.py +10 -0
  53. xinference/thirdparty/f5_tts/model/backbones/README.md +20 -0
  54. xinference/thirdparty/f5_tts/model/backbones/dit.py +163 -0
  55. xinference/thirdparty/f5_tts/model/backbones/mmdit.py +146 -0
  56. xinference/thirdparty/f5_tts/model/backbones/unett.py +219 -0
  57. xinference/thirdparty/f5_tts/model/cfm.py +285 -0
  58. xinference/thirdparty/f5_tts/model/dataset.py +319 -0
  59. xinference/thirdparty/f5_tts/model/modules.py +658 -0
  60. xinference/thirdparty/f5_tts/model/trainer.py +366 -0
  61. xinference/thirdparty/f5_tts/model/utils.py +185 -0
  62. xinference/thirdparty/f5_tts/scripts/count_max_epoch.py +33 -0
  63. xinference/thirdparty/f5_tts/scripts/count_params_gflops.py +39 -0
  64. xinference/thirdparty/f5_tts/socket_server.py +159 -0
  65. xinference/thirdparty/f5_tts/train/README.md +77 -0
  66. xinference/thirdparty/f5_tts/train/datasets/prepare_csv_wavs.py +139 -0
  67. xinference/thirdparty/f5_tts/train/datasets/prepare_emilia.py +230 -0
  68. xinference/thirdparty/f5_tts/train/datasets/prepare_libritts.py +92 -0
  69. xinference/thirdparty/f5_tts/train/datasets/prepare_ljspeech.py +65 -0
  70. xinference/thirdparty/f5_tts/train/datasets/prepare_wenetspeech4tts.py +125 -0
  71. xinference/thirdparty/f5_tts/train/finetune_cli.py +174 -0
  72. xinference/thirdparty/f5_tts/train/finetune_gradio.py +1846 -0
  73. xinference/thirdparty/f5_tts/train/train.py +75 -0
  74. xinference/web/ui/build/asset-manifest.json +3 -3
  75. xinference/web/ui/build/index.html +1 -1
  76. xinference/web/ui/build/static/js/{main.2f269bb3.js → main.4eb4ee80.js} +3 -3
  77. xinference/web/ui/build/static/js/main.4eb4ee80.js.map +1 -0
  78. xinference/web/ui/node_modules/.cache/babel-loader/8c5eeb02f772d02cbe8b89c05428d0dd41a97866f75f7dc1c2164a67f5a1cf98.json +1 -0
  79. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/METADATA +33 -14
  80. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/RECORD +85 -34
  81. xinference/web/ui/build/static/js/main.2f269bb3.js.map +0 -1
  82. xinference/web/ui/node_modules/.cache/babel-loader/bd6ad8159341315a1764c397621a560809f7eb7219ab5174c801fca7e969d943.json +0 -1
  83. /xinference/web/ui/build/static/js/{main.2f269bb3.js.LICENSE.txt → main.4eb4ee80.js.LICENSE.txt} +0 -0
  84. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/LICENSE +0 -0
  85. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/WHEEL +0 -0
  86. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/entry_points.txt +0 -0
  87. {xinference-1.0.1.dist-info → xinference-1.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,226 @@
1
+ import argparse
2
+ import codecs
3
+ import os
4
+ import re
5
+ from importlib.resources import files
6
+ from pathlib import Path
7
+
8
+ import numpy as np
9
+ import soundfile as sf
10
+ import tomli
11
+ from cached_path import cached_path
12
+
13
+ from f5_tts.infer.utils_infer import (
14
+ infer_process,
15
+ load_model,
16
+ load_vocoder,
17
+ preprocess_ref_audio_text,
18
+ remove_silence_for_generated_wav,
19
+ )
20
+ from f5_tts.model import DiT, UNetT
21
+
22
+ parser = argparse.ArgumentParser(
23
+ prog="python3 infer-cli.py",
24
+ description="Commandline interface for E2/F5 TTS with Advanced Batch Processing.",
25
+ epilog="Specify options above to override one or more settings from config.",
26
+ )
27
+ parser.add_argument(
28
+ "-c",
29
+ "--config",
30
+ help="Configuration file. Default=infer/examples/basic/basic.toml",
31
+ default=os.path.join(files("f5_tts").joinpath("infer/examples/basic"), "basic.toml"),
32
+ )
33
+ parser.add_argument(
34
+ "-m",
35
+ "--model",
36
+ help="F5-TTS | E2-TTS",
37
+ )
38
+ parser.add_argument(
39
+ "-p",
40
+ "--ckpt_file",
41
+ help="The Checkpoint .pt",
42
+ )
43
+ parser.add_argument(
44
+ "-v",
45
+ "--vocab_file",
46
+ help="The vocab .txt",
47
+ )
48
+ parser.add_argument("-r", "--ref_audio", type=str, help="Reference audio file < 15 seconds.")
49
+ parser.add_argument("-s", "--ref_text", type=str, default="666", help="Subtitle for the reference audio.")
50
+ parser.add_argument(
51
+ "-t",
52
+ "--gen_text",
53
+ type=str,
54
+ help="Text to generate.",
55
+ )
56
+ parser.add_argument(
57
+ "-f",
58
+ "--gen_file",
59
+ type=str,
60
+ help="File with text to generate. Ignores --gen_text",
61
+ )
62
+ parser.add_argument(
63
+ "-o",
64
+ "--output_dir",
65
+ type=str,
66
+ help="Path to output folder..",
67
+ )
68
+ parser.add_argument(
69
+ "-w",
70
+ "--output_file",
71
+ type=str,
72
+ help="Filename of output file..",
73
+ )
74
+ parser.add_argument(
75
+ "--remove_silence",
76
+ help="Remove silence.",
77
+ )
78
+ parser.add_argument("--vocoder_name", type=str, default="vocos", choices=["vocos", "bigvgan"], help="vocoder name")
79
+ parser.add_argument(
80
+ "--load_vocoder_from_local",
81
+ action="store_true",
82
+ help="load vocoder from local. Default: ../checkpoints/charactr/vocos-mel-24khz",
83
+ )
84
+ parser.add_argument(
85
+ "--speed",
86
+ type=float,
87
+ default=1.0,
88
+ help="Adjust the speed of the audio generation (default: 1.0)",
89
+ )
90
+ args = parser.parse_args()
91
+
92
+ config = tomli.load(open(args.config, "rb"))
93
+
94
+ ref_audio = args.ref_audio if args.ref_audio else config["ref_audio"]
95
+ ref_text = args.ref_text if args.ref_text != "666" else config["ref_text"]
96
+ gen_text = args.gen_text if args.gen_text else config["gen_text"]
97
+ gen_file = args.gen_file if args.gen_file else config["gen_file"]
98
+
99
+ # patches for pip pkg user
100
+ if "infer/examples/" in ref_audio:
101
+ ref_audio = str(files("f5_tts").joinpath(f"{ref_audio}"))
102
+ if "infer/examples/" in gen_file:
103
+ gen_file = str(files("f5_tts").joinpath(f"{gen_file}"))
104
+ if "voices" in config:
105
+ for voice in config["voices"]:
106
+ voice_ref_audio = config["voices"][voice]["ref_audio"]
107
+ if "infer/examples/" in voice_ref_audio:
108
+ config["voices"][voice]["ref_audio"] = str(files("f5_tts").joinpath(f"{voice_ref_audio}"))
109
+
110
+ if gen_file:
111
+ gen_text = codecs.open(gen_file, "r", "utf-8").read()
112
+ output_dir = args.output_dir if args.output_dir else config["output_dir"]
113
+ output_file = args.output_file if args.output_file else config["output_file"]
114
+ model = args.model if args.model else config["model"]
115
+ ckpt_file = args.ckpt_file if args.ckpt_file else ""
116
+ vocab_file = args.vocab_file if args.vocab_file else ""
117
+ remove_silence = args.remove_silence if args.remove_silence else config["remove_silence"]
118
+ speed = args.speed
119
+
120
+ wave_path = Path(output_dir) / output_file
121
+ # spectrogram_path = Path(output_dir) / "infer_cli_out.png"
122
+
123
+ vocoder_name = args.vocoder_name
124
+ mel_spec_type = args.vocoder_name
125
+ if vocoder_name == "vocos":
126
+ vocoder_local_path = "../checkpoints/vocos-mel-24khz"
127
+ elif vocoder_name == "bigvgan":
128
+ vocoder_local_path = "../checkpoints/bigvgan_v2_24khz_100band_256x"
129
+
130
+ vocoder = load_vocoder(vocoder_name=mel_spec_type, is_local=args.load_vocoder_from_local, local_path=vocoder_local_path)
131
+
132
+
133
+ # load models
134
+ if model == "F5-TTS":
135
+ model_cls = DiT
136
+ model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)
137
+ if ckpt_file == "":
138
+ if vocoder_name == "vocos":
139
+ repo_name = "F5-TTS"
140
+ exp_name = "F5TTS_Base"
141
+ ckpt_step = 1200000
142
+ ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors"))
143
+ # ckpt_file = f"ckpts/{exp_name}/model_{ckpt_step}.pt" # .pt | .safetensors; local path
144
+ elif vocoder_name == "bigvgan":
145
+ repo_name = "F5-TTS"
146
+ exp_name = "F5TTS_Base_bigvgan"
147
+ ckpt_step = 1250000
148
+ ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.pt"))
149
+
150
+ elif model == "E2-TTS":
151
+ assert vocoder_name == "vocos", "E2-TTS only supports vocoder vocos"
152
+ model_cls = UNetT
153
+ model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)
154
+ if ckpt_file == "":
155
+ repo_name = "E2-TTS"
156
+ exp_name = "E2TTS_Base"
157
+ ckpt_step = 1200000
158
+ ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors"))
159
+ # ckpt_file = f"ckpts/{exp_name}/model_{ckpt_step}.pt" # .pt | .safetensors; local path
160
+
161
+
162
+ print(f"Using {model}...")
163
+ ema_model = load_model(model_cls, model_cfg, ckpt_file, mel_spec_type=mel_spec_type, vocab_file=vocab_file)
164
+
165
+
166
+ def main_process(ref_audio, ref_text, text_gen, model_obj, mel_spec_type, remove_silence, speed):
167
+ main_voice = {"ref_audio": ref_audio, "ref_text": ref_text}
168
+ if "voices" not in config:
169
+ voices = {"main": main_voice}
170
+ else:
171
+ voices = config["voices"]
172
+ voices["main"] = main_voice
173
+ for voice in voices:
174
+ voices[voice]["ref_audio"], voices[voice]["ref_text"] = preprocess_ref_audio_text(
175
+ voices[voice]["ref_audio"], voices[voice]["ref_text"]
176
+ )
177
+ print("Voice:", voice)
178
+ print("Ref_audio:", voices[voice]["ref_audio"])
179
+ print("Ref_text:", voices[voice]["ref_text"])
180
+
181
+ generated_audio_segments = []
182
+ reg1 = r"(?=\[\w+\])"
183
+ chunks = re.split(reg1, text_gen)
184
+ reg2 = r"\[(\w+)\]"
185
+ for text in chunks:
186
+ if not text.strip():
187
+ continue
188
+ match = re.match(reg2, text)
189
+ if match:
190
+ voice = match[1]
191
+ else:
192
+ print("No voice tag found, using main.")
193
+ voice = "main"
194
+ if voice not in voices:
195
+ print(f"Voice {voice} not found, using main.")
196
+ voice = "main"
197
+ text = re.sub(reg2, "", text)
198
+ gen_text = text.strip()
199
+ ref_audio = voices[voice]["ref_audio"]
200
+ ref_text = voices[voice]["ref_text"]
201
+ print(f"Voice: {voice}")
202
+ audio, final_sample_rate, spectragram = infer_process(
203
+ ref_audio, ref_text, gen_text, model_obj, vocoder, mel_spec_type=mel_spec_type, speed=speed
204
+ )
205
+ generated_audio_segments.append(audio)
206
+
207
+ if generated_audio_segments:
208
+ final_wave = np.concatenate(generated_audio_segments)
209
+
210
+ if not os.path.exists(output_dir):
211
+ os.makedirs(output_dir)
212
+
213
+ with open(wave_path, "wb") as f:
214
+ sf.write(f.name, final_wave, final_sample_rate)
215
+ # Remove silence
216
+ if remove_silence:
217
+ remove_silence_for_generated_wav(f.name)
218
+ print(f.name)
219
+
220
+
221
+ def main():
222
+ main_process(ref_audio, ref_text, gen_text, ema_model, mel_spec_type, remove_silence, speed)
223
+
224
+
225
+ if __name__ == "__main__":
226
+ main()