lollms-client 1.6.1__py3-none-any.whl → 1.6.4__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 lollms-client might be problematic. Click here for more details.
- lollms_client/__init__.py +1 -1
- lollms_client/llm_bindings/azure_openai/__init__.py +2 -2
- lollms_client/llm_bindings/claude/__init__.py +2 -2
- lollms_client/llm_bindings/gemini/__init__.py +2 -2
- lollms_client/llm_bindings/grok/__init__.py +2 -2
- lollms_client/llm_bindings/groq/__init__.py +2 -2
- lollms_client/llm_bindings/hugging_face_inference_api/__init__.py +2 -2
- lollms_client/llm_bindings/litellm/__init__.py +1 -1
- lollms_client/llm_bindings/llamacpp/__init__.py +2 -2
- lollms_client/llm_bindings/lollms/__init__.py +1 -1
- lollms_client/llm_bindings/lollms_webui/__init__.py +1 -1
- lollms_client/llm_bindings/mistral/__init__.py +2 -2
- lollms_client/llm_bindings/novita_ai/__init__.py +2 -2
- lollms_client/llm_bindings/ollama/__init__.py +7 -4
- lollms_client/llm_bindings/open_router/__init__.py +2 -2
- lollms_client/llm_bindings/openai/__init__.py +1 -1
- lollms_client/llm_bindings/openllm/__init__.py +2 -2
- lollms_client/llm_bindings/openwebui/__init__.py +1 -1
- lollms_client/llm_bindings/perplexity/__init__.py +2 -2
- lollms_client/llm_bindings/pythonllamacpp/__init__.py +3 -3
- lollms_client/llm_bindings/tensor_rt/__init__.py +1 -1
- lollms_client/llm_bindings/transformers/__init__.py +4 -4
- lollms_client/llm_bindings/vllm/__init__.py +1 -1
- lollms_client/lollms_core.py +19 -1452
- lollms_client/lollms_llm_binding.py +1 -1
- lollms_client/lollms_tti_binding.py +1 -1
- lollms_client/lollms_tts_binding.py +15 -13
- lollms_client/tti_bindings/diffusers/__init__.py +276 -856
- lollms_client/tti_bindings/diffusers/server/main.py +730 -0
- lollms_client/tti_bindings/gemini/__init__.py +1 -1
- lollms_client/tti_bindings/leonardo_ai/__init__.py +1 -1
- lollms_client/tti_bindings/novita_ai/__init__.py +1 -1
- lollms_client/tti_bindings/stability_ai/__init__.py +1 -1
- lollms_client/tts_bindings/lollms/__init__.py +6 -1
- lollms_client/tts_bindings/piper_tts/__init__.py +1 -1
- lollms_client/tts_bindings/xtts/__init__.py +97 -38
- lollms_client/tts_bindings/xtts/server/main.py +288 -272
- {lollms_client-1.6.1.dist-info → lollms_client-1.6.4.dist-info}/METADATA +6 -3
- {lollms_client-1.6.1.dist-info → lollms_client-1.6.4.dist-info}/RECORD +42 -41
- {lollms_client-1.6.1.dist-info → lollms_client-1.6.4.dist-info}/WHEEL +0 -0
- {lollms_client-1.6.1.dist-info → lollms_client-1.6.4.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-1.6.1.dist-info → lollms_client-1.6.4.dist-info}/top_level.txt +0 -0
|
@@ -1,314 +1,330 @@
|
|
|
1
|
-
import uvicorn
|
|
2
|
-
from fastapi import FastAPI, APIRouter, HTTPException
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
import argparse
|
|
5
|
-
import sys
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import asyncio
|
|
8
|
-
import traceback
|
|
9
|
-
import os
|
|
10
|
-
from typing import Optional, List
|
|
11
|
-
import io
|
|
12
|
-
import wave
|
|
13
|
-
import numpy as np
|
|
14
|
-
import tempfile
|
|
15
|
-
|
|
16
|
-
# --- XTTS Implementation ---
|
|
17
1
|
try:
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
33
|
-
xtts_available = False
|
|
34
|
-
|
|
35
|
-
# --- API Models ---
|
|
36
|
-
class GenerationRequest(BaseModel):
|
|
37
|
-
text: str
|
|
38
|
-
voice: Optional[str] = None
|
|
39
|
-
language: Optional[str] = "en"
|
|
40
|
-
speaker_wav: Optional[str] = None
|
|
2
|
+
import uvicorn
|
|
3
|
+
from fastapi import FastAPI, APIRouter, HTTPException
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import asyncio
|
|
9
|
+
import traceback
|
|
10
|
+
import os
|
|
11
|
+
from typing import Optional, List
|
|
12
|
+
import io
|
|
13
|
+
import wave
|
|
14
|
+
import numpy as np
|
|
15
|
+
import tempfile
|
|
41
16
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
17
|
+
# --- XTTS Implementation ---
|
|
18
|
+
try:
|
|
19
|
+
print("Server: Loading XTTS dependencies...")
|
|
20
|
+
import torch
|
|
21
|
+
import torchaudio
|
|
22
|
+
from TTS.api import TTS
|
|
23
|
+
print("Server: XTTS dependencies loaded successfully")
|
|
49
24
|
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# Initialize XTTS model
|
|
72
|
-
self.model = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
|
73
|
-
|
|
74
|
-
self.model_loaded = True
|
|
75
|
-
print("Server: XTTS model loaded successfully")
|
|
76
|
-
|
|
77
|
-
except Exception as e:
|
|
78
|
-
print(f"Server: Error loading XTTS model: {e}")
|
|
79
|
-
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
25
|
+
# Check for CUDA availability
|
|
26
|
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
27
|
+
print(f"Server: Using device: {device}")
|
|
28
|
+
|
|
29
|
+
xtts_available = True
|
|
30
|
+
|
|
31
|
+
except Exception as e:
|
|
32
|
+
print(f"Server: Failed to load XTTS dependencies: {e}")
|
|
33
|
+
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
34
|
+
xtts_available = False
|
|
35
|
+
|
|
36
|
+
# --- API Models ---
|
|
37
|
+
class GenerationRequest(BaseModel):
|
|
38
|
+
text: str
|
|
39
|
+
voice: Optional[str] = None
|
|
40
|
+
language: Optional[str] = "en"
|
|
41
|
+
speaker_wav: Optional[str] = None
|
|
42
|
+
|
|
43
|
+
class XTTSServer:
|
|
44
|
+
def __init__(self):
|
|
45
|
+
self.model = None
|
|
80
46
|
self.model_loaded = False
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
self.
|
|
84
|
-
|
|
85
|
-
def _load_available_voices(self) -> List[str]:
|
|
86
|
-
"""Load and return available voices"""
|
|
87
|
-
try:
|
|
88
|
-
# Look for voice files in voices directory
|
|
89
|
-
voices_dir = Path(__file__).parent / "voices"
|
|
90
|
-
voices = []
|
|
47
|
+
self.model_loading = False # Flag to prevent concurrent loading
|
|
48
|
+
self.available_voices = self._load_available_voices()
|
|
49
|
+
self.available_models = ["xtts_v2"]
|
|
91
50
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
voices = ["default", "female", "male"]
|
|
51
|
+
# Don't initialize model here - do it lazily on first request
|
|
52
|
+
print("Server: XTTS server initialized (model will be loaded on first request)")
|
|
53
|
+
|
|
54
|
+
async def _ensure_model_loaded(self):
|
|
55
|
+
"""Ensure the XTTS model is loaded (lazy loading)"""
|
|
56
|
+
if self.model_loaded:
|
|
57
|
+
return
|
|
100
58
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
59
|
+
if self.model_loading:
|
|
60
|
+
# Another request is already loading the model, wait for it
|
|
61
|
+
while self.model_loading and not self.model_loaded:
|
|
62
|
+
await asyncio.sleep(0.1)
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
if not xtts_available:
|
|
66
|
+
raise RuntimeError("XTTS library not available")
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
self.model_loading = True
|
|
70
|
+
print("Server: Loading XTTS model for the first time (this may take a few minutes)...")
|
|
71
|
+
|
|
72
|
+
# Initialize XTTS model
|
|
73
|
+
self.model = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
|
74
|
+
|
|
75
|
+
self.model_loaded = True
|
|
76
|
+
print("Server: XTTS model loaded successfully")
|
|
77
|
+
|
|
78
|
+
except Exception as e:
|
|
79
|
+
print(f"Server: Error loading XTTS model: {e}")
|
|
80
|
+
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
81
|
+
self.model_loaded = False
|
|
82
|
+
raise
|
|
83
|
+
finally:
|
|
84
|
+
self.model_loading = False
|
|
112
85
|
|
|
113
|
-
|
|
114
|
-
|
|
86
|
+
def _load_available_voices(self) -> List[str]:
|
|
87
|
+
"""Load and return available voices"""
|
|
88
|
+
try:
|
|
89
|
+
# Look for voice files in voices directory
|
|
90
|
+
voices_dir = Path(__file__).parent / "voices"
|
|
91
|
+
voices = []
|
|
92
|
+
|
|
93
|
+
if voices_dir.exists():
|
|
94
|
+
# Look for WAV files in voices directory
|
|
95
|
+
for voice_file in voices_dir.glob("*.wav"):
|
|
96
|
+
voices.append(voice_file.stem)
|
|
97
|
+
|
|
98
|
+
# If no custom voices found, provide some default names
|
|
99
|
+
if not voices:
|
|
100
|
+
voices = ["default", "female", "male"]
|
|
101
|
+
|
|
102
|
+
return voices
|
|
103
|
+
|
|
104
|
+
except Exception as e:
|
|
105
|
+
print(f"Server: Error loading voices: {e}")
|
|
106
|
+
return ["default"]
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
speaker_wav_path = None
|
|
108
|
+
async def generate_audio(self, text: str, voice: Optional[str] = None,
|
|
109
|
+
language: str = "en", speaker_wav: Optional[str] = None) -> bytes:
|
|
110
|
+
"""Generate audio from text using XTTS"""
|
|
111
|
+
# Ensure model is loaded before proceeding
|
|
112
|
+
await self._ensure_model_loaded()
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
speaker_wav_path = speaker_wav
|
|
126
|
-
print(f"Server: Using provided speaker_wav: {speaker_wav_path}")
|
|
114
|
+
if not self.model_loaded or self.model is None:
|
|
115
|
+
raise RuntimeError("XTTS model failed to load")
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
try:
|
|
118
|
+
print(f"Server: Generating audio for: '{text[:50]}{'...' if len(text) > 50 else ''}'")
|
|
119
|
+
print(f"Server: Using voice: {voice}, language: {language}")
|
|
120
|
+
|
|
121
|
+
# Handle voice/speaker selection
|
|
122
|
+
speaker_wav_path = None
|
|
123
|
+
|
|
124
|
+
# First priority: use provided speaker_wav parameter
|
|
125
|
+
if speaker_wav:
|
|
126
|
+
speaker_wav_path = speaker_wav
|
|
127
|
+
print(f"Server: Using provided speaker_wav: {speaker_wav_path}")
|
|
128
|
+
|
|
129
|
+
# Second priority: check if voice parameter is a file path
|
|
130
|
+
elif voice and voice != "default":
|
|
131
|
+
if os.path.exists(voice):
|
|
132
|
+
# Voice parameter is a full file path
|
|
133
|
+
speaker_wav_path = voice
|
|
134
|
+
print(f"Server: Using voice as file path: {speaker_wav_path}")
|
|
135
|
+
else:
|
|
136
|
+
# Look for voice file in voices directory
|
|
137
|
+
voices_dir = Path(__file__).parent / "voices"
|
|
138
|
+
potential_voice_path = voices_dir / f"{voice}.wav"
|
|
139
|
+
if potential_voice_path.exists():
|
|
140
|
+
speaker_wav_path = str(potential_voice_path)
|
|
141
|
+
print(f"Server: Using custom voice file: {speaker_wav_path}")
|
|
142
|
+
else:
|
|
143
|
+
print(f"Server: Voice '{voice}' not found in voices directory")
|
|
134
144
|
else:
|
|
145
|
+
voice = "default_voice"
|
|
135
146
|
# Look for voice file in voices directory
|
|
136
147
|
voices_dir = Path(__file__).parent / "voices"
|
|
137
|
-
potential_voice_path = voices_dir / f"{voice}.
|
|
148
|
+
potential_voice_path = voices_dir / f"{voice}.mp3"
|
|
138
149
|
if potential_voice_path.exists():
|
|
139
150
|
speaker_wav_path = str(potential_voice_path)
|
|
140
151
|
print(f"Server: Using custom voice file: {speaker_wav_path}")
|
|
141
152
|
else:
|
|
142
153
|
print(f"Server: Voice '{voice}' not found in voices directory")
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
print(f"Server: Generating with speaker reference: {speaker_wav_path}")
|
|
152
|
-
self.model.tts_to_file(
|
|
153
|
-
text=text,
|
|
154
|
-
speaker_wav=speaker_wav_path,
|
|
155
|
-
language=language,
|
|
156
|
-
file_path=temp_output_path
|
|
157
|
-
)
|
|
158
|
-
else:
|
|
159
|
-
print("Server: No valid speaker reference found, trying default")
|
|
160
|
-
# For XTTS without speaker reference, try to find a default
|
|
161
|
-
default_speaker = self._get_default_speaker_file()
|
|
162
|
-
if default_speaker and os.path.exists(default_speaker):
|
|
163
|
-
print(f"Server: Using default speaker: {default_speaker}")
|
|
154
|
+
# Create a temporary file for output
|
|
155
|
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
|
156
|
+
temp_output_path = temp_file.name
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
# Generate audio using XTTS
|
|
160
|
+
if speaker_wav_path and os.path.exists(speaker_wav_path):
|
|
161
|
+
print(f"Server: Generating with speaker reference: {speaker_wav_path}")
|
|
164
162
|
self.model.tts_to_file(
|
|
165
163
|
text=text,
|
|
166
|
-
speaker_wav=
|
|
164
|
+
speaker_wav=speaker_wav_path,
|
|
167
165
|
language=language,
|
|
168
166
|
file_path=temp_output_path
|
|
169
167
|
)
|
|
170
168
|
else:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
169
|
+
print("Server: No valid speaker reference found, trying default")
|
|
170
|
+
# For XTTS without speaker reference, try to find a default
|
|
171
|
+
default_speaker = self._get_default_speaker_file()
|
|
172
|
+
if default_speaker and os.path.exists(default_speaker):
|
|
173
|
+
print(f"Server: Using default speaker: {default_speaker}")
|
|
174
|
+
self.model.tts_to_file(
|
|
175
|
+
text=text,
|
|
176
|
+
speaker_wav=default_speaker,
|
|
177
|
+
language=language,
|
|
178
|
+
file_path=temp_output_path
|
|
179
|
+
)
|
|
180
|
+
else:
|
|
181
|
+
# Create a more helpful error message
|
|
182
|
+
available_voices = self._get_all_available_voice_files()
|
|
183
|
+
error_msg = f"No speaker reference available. XTTS requires a speaker reference file.\n"
|
|
184
|
+
error_msg += f"Attempted to use: {speaker_wav_path if speaker_wav_path else 'None'}\n"
|
|
185
|
+
error_msg += f"Available voice files: {available_voices}"
|
|
186
|
+
raise RuntimeError(error_msg)
|
|
187
|
+
|
|
188
|
+
# Read the generated audio file
|
|
189
|
+
with open(temp_output_path, 'rb') as f:
|
|
190
|
+
audio_bytes = f.read()
|
|
191
|
+
|
|
192
|
+
print(f"Server: Generated {len(audio_bytes)} bytes of audio")
|
|
193
|
+
return audio_bytes
|
|
194
|
+
|
|
195
|
+
finally:
|
|
196
|
+
# Clean up temporary file
|
|
197
|
+
if os.path.exists(temp_output_path):
|
|
198
|
+
os.unlink(temp_output_path)
|
|
184
199
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
except Exception as e:
|
|
191
|
-
print(f"Server: Error generating audio: {e}")
|
|
192
|
-
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
193
|
-
raise
|
|
194
|
-
|
|
195
|
-
def _get_all_available_voice_files(self) -> List[str]:
|
|
196
|
-
"""Get list of all available voice files for debugging"""
|
|
197
|
-
voices_dir = Path(__file__).parent / "voices"
|
|
198
|
-
voice_files = []
|
|
200
|
+
except Exception as e:
|
|
201
|
+
print(f"Server: Error generating audio: {e}")
|
|
202
|
+
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
203
|
+
raise
|
|
199
204
|
|
|
200
|
-
|
|
201
|
-
|
|
205
|
+
def _get_all_available_voice_files(self) -> List[str]:
|
|
206
|
+
"""Get list of all available voice files for debugging"""
|
|
207
|
+
voices_dir = Path(__file__).parent / "voices"
|
|
208
|
+
voice_files = []
|
|
202
209
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
voices_dir = Path(__file__).parent / "voices"
|
|
210
|
+
if voices_dir.exists():
|
|
211
|
+
voice_files = [str(f) for f in voices_dir.glob("*.wav")]
|
|
212
|
+
|
|
213
|
+
return voice_files
|
|
208
214
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
215
|
+
def _get_default_speaker_file(self) -> Optional[str]:
|
|
216
|
+
"""Get path to default speaker file"""
|
|
217
|
+
voices_dir = Path(__file__).parent / "voices"
|
|
218
|
+
|
|
219
|
+
# Look for a default speaker file
|
|
220
|
+
for filename in ["default.wav", "speaker.wav", "reference.wav"]:
|
|
221
|
+
potential_path = voices_dir / filename
|
|
222
|
+
if potential_path.exists():
|
|
223
|
+
return str(potential_path)
|
|
224
|
+
|
|
225
|
+
# If no default found, look for any wav file
|
|
226
|
+
wav_files = list(voices_dir.glob("*.wav"))
|
|
227
|
+
if wav_files:
|
|
228
|
+
return str(wav_files[0])
|
|
229
|
+
|
|
230
|
+
return None
|
|
214
231
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return str(wav_files[0])
|
|
232
|
+
def list_voices(self) -> List[str]:
|
|
233
|
+
"""Return list of available voices"""
|
|
234
|
+
return self.available_voices
|
|
219
235
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"""Return list of available voices"""
|
|
224
|
-
return self.available_voices
|
|
225
|
-
|
|
226
|
-
def list_models(self) -> List[str]:
|
|
227
|
-
"""Return list of available models"""
|
|
228
|
-
return self.available_models
|
|
236
|
+
def list_models(self) -> List[str]:
|
|
237
|
+
"""Return list of available models"""
|
|
238
|
+
return self.available_models
|
|
229
239
|
|
|
230
|
-
# --- Globals ---
|
|
231
|
-
app = FastAPI(title="XTTS Server")
|
|
232
|
-
router = APIRouter()
|
|
233
|
-
xtts_server = XTTSServer()
|
|
234
|
-
model_lock = asyncio.Lock() # Ensure thread-safe access
|
|
240
|
+
# --- Globals ---
|
|
241
|
+
app = FastAPI(title="XTTS Server")
|
|
242
|
+
router = APIRouter()
|
|
243
|
+
xtts_server = XTTSServer()
|
|
244
|
+
model_lock = asyncio.Lock() # Ensure thread-safe access
|
|
235
245
|
|
|
236
|
-
# --- API Endpoints ---
|
|
237
|
-
@router.post("/generate_audio")
|
|
238
|
-
async def generate_audio(request: GenerationRequest):
|
|
239
|
-
|
|
246
|
+
# --- API Endpoints ---
|
|
247
|
+
@router.post("/generate_audio")
|
|
248
|
+
async def generate_audio(request: GenerationRequest):
|
|
249
|
+
async with model_lock:
|
|
250
|
+
try:
|
|
251
|
+
print(f"request.language:{request.language}")
|
|
252
|
+
audio_bytes = await xtts_server.generate_audio(
|
|
253
|
+
text=request.text,
|
|
254
|
+
voice=request.voice,
|
|
255
|
+
language=request.language,
|
|
256
|
+
speaker_wav=request.speaker_wav
|
|
257
|
+
)
|
|
258
|
+
from fastapi.responses import Response
|
|
259
|
+
return Response(content=audio_bytes, media_type="audio/wav")
|
|
260
|
+
except Exception as e:
|
|
261
|
+
print(f"Server: ERROR in generate_audio endpoint: {e}")
|
|
262
|
+
print(f"Server: ERROR traceback:\n{traceback.format_exc()}")
|
|
263
|
+
raise HTTPException(status_code=500, detail=str(e))
|
|
264
|
+
|
|
265
|
+
@router.get("/list_voices")
|
|
266
|
+
async def list_voices():
|
|
240
267
|
try:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
language=request.language,
|
|
245
|
-
speaker_wav=request.speaker_wav
|
|
246
|
-
)
|
|
247
|
-
from fastapi.responses import Response
|
|
248
|
-
return Response(content=audio_bytes, media_type="audio/wav")
|
|
268
|
+
voices = xtts_server.list_voices()
|
|
269
|
+
print(f"Server: Returning {len(voices)} voices: {voices}")
|
|
270
|
+
return {"voices": voices}
|
|
249
271
|
except Exception as e:
|
|
250
|
-
print(f"Server: ERROR in
|
|
272
|
+
print(f"Server: ERROR in list_voices endpoint: {e}")
|
|
251
273
|
print(f"Server: ERROR traceback:\n{traceback.format_exc()}")
|
|
252
274
|
raise HTTPException(status_code=500, detail=str(e))
|
|
253
275
|
|
|
254
|
-
@router.get("/
|
|
255
|
-
async def
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
@router.get("/list_models")
|
|
266
|
-
async def list_models():
|
|
267
|
-
try:
|
|
268
|
-
models = xtts_server.list_models()
|
|
269
|
-
print(f"Server: Returning {len(models)} models: {models}")
|
|
270
|
-
return {"models": models}
|
|
271
|
-
except Exception as e:
|
|
272
|
-
print(f"Server: ERROR in list_models endpoint: {e}")
|
|
273
|
-
print(f"Server: ERROR traceback:\n{traceback.format_exc()}")
|
|
274
|
-
raise HTTPException(status_code=500, detail=str(e))
|
|
276
|
+
@router.get("/list_models")
|
|
277
|
+
async def list_models():
|
|
278
|
+
try:
|
|
279
|
+
models = xtts_server.list_models()
|
|
280
|
+
print(f"Server: Returning {len(models)} models: {models}")
|
|
281
|
+
return {"models": models}
|
|
282
|
+
except Exception as e:
|
|
283
|
+
print(f"Server: ERROR in list_models endpoint: {e}")
|
|
284
|
+
print(f"Server: ERROR traceback:\n{traceback.format_exc()}")
|
|
285
|
+
raise HTTPException(status_code=500, detail=str(e))
|
|
275
286
|
|
|
276
|
-
@router.get("/status")
|
|
277
|
-
async def status():
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
287
|
+
@router.get("/status")
|
|
288
|
+
async def status():
|
|
289
|
+
return {
|
|
290
|
+
"status": "running",
|
|
291
|
+
"xtts_available": xtts_available,
|
|
292
|
+
"model_loaded": xtts_server.model_loaded,
|
|
293
|
+
"model_loading": xtts_server.model_loading,
|
|
294
|
+
"voices_count": len(xtts_server.available_voices),
|
|
295
|
+
"device": torch.cuda.get_device_name(0) if torch.cuda.is_available() else "CPU"
|
|
296
|
+
}
|
|
286
297
|
|
|
287
|
-
# Add a health check endpoint that responds immediately
|
|
288
|
-
@router.get("/health")
|
|
289
|
-
async def health_check():
|
|
290
|
-
|
|
298
|
+
# Add a health check endpoint that responds immediately
|
|
299
|
+
@router.get("/health")
|
|
300
|
+
async def health_check():
|
|
301
|
+
return {"status": "healthy", "ready": True}
|
|
291
302
|
|
|
292
|
-
app.include_router(router)
|
|
303
|
+
app.include_router(router)
|
|
293
304
|
|
|
294
|
-
# --- Server Startup ---
|
|
295
|
-
if __name__ == '__main__':
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
305
|
+
# --- Server Startup ---
|
|
306
|
+
if __name__ == '__main__':
|
|
307
|
+
parser = argparse.ArgumentParser(description="XTTS TTS Server")
|
|
308
|
+
parser.add_argument("--host", type=str, default="localhost", help="Host to bind the server to.")
|
|
309
|
+
parser.add_argument("--port", type=int, default="96", help="Port to bind the server to.")
|
|
310
|
+
|
|
311
|
+
args = parser.parse_args()
|
|
301
312
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
print(f"Server: Starting XTTS server on {args.host}:{args.port}")
|
|
314
|
+
print(f"Server: XTTS available: {xtts_available}")
|
|
315
|
+
print(f"Server: Model will be loaded on first audio generation request")
|
|
316
|
+
print(f"Server: Available voices: {len(xtts_server.available_voices)}")
|
|
317
|
+
if xtts_available:
|
|
318
|
+
print(f"Server: Device: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}")
|
|
319
|
+
|
|
320
|
+
# Create voices directory if it doesn't exist
|
|
321
|
+
voices_dir = Path(__file__).parent / "voices"
|
|
322
|
+
voices_dir.mkdir(exist_ok=True)
|
|
323
|
+
print(f"Server: Voices directory: {voices_dir}")
|
|
324
|
+
try:
|
|
325
|
+
uvicorn.run(app, host=args.host, port=args.port)
|
|
326
|
+
except Exception as e:
|
|
327
|
+
print(f"Server: CRITICAL ERROR running server: {e}")
|
|
328
|
+
print(f"Server: Traceback:\n{traceback.format_exc()}")
|
|
329
|
+
except Exception as e:
|
|
330
|
+
print(f"Server: CRITICAL ERROR during startup: {e}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lollms_client
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.4
|
|
4
4
|
Summary: A client library for LoLLMs generate endpoint
|
|
5
5
|
Author-email: ParisNeo <parisneoai@gmail.com>
|
|
6
6
|
License: Apache License
|
|
@@ -1302,6 +1302,7 @@ try:
|
|
|
1302
1302
|
except Exception as e:
|
|
1303
1303
|
ASCIIColors.error(f"Error initializing Hugging Face Inference API binding: {e}")
|
|
1304
1304
|
ASCIIColors.info("Please ensure your Hugging Face API token is correctly set and you have access to the specified model.")```
|
|
1305
|
+
```
|
|
1305
1306
|
|
|
1306
1307
|
---
|
|
1307
1308
|
|
|
@@ -1403,7 +1404,9 @@ else:
|
|
|
1403
1404
|
|
|
1404
1405
|
except Exception as e:
|
|
1405
1406
|
ASCIIColors.error(f"An error occurred during multi-image fusion: {e}")
|
|
1406
|
-
```
|
|
1407
|
+
```
|
|
1408
|
+
|
|
1409
|
+
This powerful feature allows for complex creative tasks like character swapping, background replacement, and style transfer directly through the `lollms_client` library.
|
|
1407
1410
|
|
|
1408
1411
|
### Listing Available Models
|
|
1409
1412
|
|
|
@@ -1425,7 +1428,7 @@ try:
|
|
|
1425
1428
|
)
|
|
1426
1429
|
|
|
1427
1430
|
ASCIIColors.yellow("\nListing available models for the current binding:")
|
|
1428
|
-
available_models = lc.
|
|
1431
|
+
available_models = lc.list_models()
|
|
1429
1432
|
|
|
1430
1433
|
if isinstance(available_models, list):
|
|
1431
1434
|
for model in available_models:
|