enhanced core

This commit is contained in:
Saifeddine ALOUI 2025-03-09 00:37:33 +01:00
parent cf4b66db4d
commit 89150191f0
2 changed files with 56 additions and 80 deletions

View File

@ -619,21 +619,8 @@ class LollmsApplication(LoLLMsCom):
ASCIIColors.execute_with_animation("Loading TTT services", start_ttt,ASCIIColors.color_blue)
def start_stt(*args, **kwargs):
if self.config.whisper_activate or self.config.active_stt_service == "whisper":
try:
from lollms.services.stt.whisper.lollms_whisper import LollmsWhisper
self.whisper = LollmsWhisper(self)
stt_services.append("whisper")
except Exception as ex:
trace_exception(ex)
if self.config.active_stt_service == "openai_whisper":
from lollms.services.stt.openai_whisper.lollms_openai_whisper import LollmsOpenAIWhisper
self.stt = LollmsOpenAIWhisper(self)
elif self.config.active_stt_service == "whisper":
from lollms.services.stt.whisper.lollms_whisper import LollmsWhisper
self.stt = LollmsWhisper(self)
ASCIIColors.execute_with_animation("Loading STT services", start_stt, ASCIIColors.color_blue)
self.stt = self.load_service_from_folder(self.lollms_paths.services_zoo_path/"stt", self.config.active_stt_service)
ASCIIColors.execute_with_animation("Loading loacal STT services", start_stt, ASCIIColors.color_blue)
def start_tts(*args, **kwargs):
if self.config.active_tts_service == "xtts":
@ -694,56 +681,19 @@ class LollmsApplication(LoLLMsCom):
trace_exception(ex)
self.warning(f"Couldn't load vllm")
ASCIIColors.blue("Loading local STT services")
if self.config.whisper_activate and self.whisper is None:
try:
from lollms.services.stt.whisper.lollms_whisper import LollmsWhisper
self.whisper = LollmsWhisper(self)
except Exception as ex:
trace_exception(ex)
ASCIIColors.blue("Loading loacal TTS services")
if self.config.active_tts_service == "xtts" and (self.tts is None or self.tts.name!="xtts"):
ASCIIColors.yellow("Loading XTTS")
try:
from lollms.services.tts.xtts.lollms_xtts import LollmsXTTS
voice=self.config.xtts_current_voice
if voice!="main_voice":
voices_folder = self.lollms_paths.custom_voices_path
else:
voices_folder = Path(__file__).parent.parent.parent/"services/xtts/voices"
self.tts = LollmsXTTS(
self
)
except Exception as ex:
trace_exception(ex)
self.warning(f"Couldn't load XTTS")
def start_tti(*args, **kwargs):
self.tti = self.load_service_from_folder(self.lollms_paths.services_zoo_path/"tti", self.config.active_tti_service)
ASCIIColors.execute_with_animation("Loading loacal TTI services", start_tti, ASCIIColors.color_blue)
ASCIIColors.blue("Activating TTS service")
if self.config.active_tts_service == "eleven_labs_tts":
from lollms.services.tts.eleven_labs_tts.lollms_eleven_labs_tts import LollmsElevenLabsTTS
self.tts = LollmsElevenLabsTTS(self)
elif self.config.active_tts_service == "openai_tts" and (self.tts is None or self.tts.name!="openai_tts"):
from lollms.services.tts.open_ai_tts.lollms_openai_tts import LollmsOpenAITTS
self.tts = LollmsOpenAITTS(self)
elif self.config.active_tts_service == "fish_tts":
from lollms.services.tts.fish.lollms_fish_tts import LollmsFishAudioTTS
self.tts = LollmsFishAudioTTS(self)
def start_stt(*args, **kwargs):
self.stt = self.load_service_from_folder(self.lollms_paths.services_zoo_path/"stt", self.config.active_stt_service)
ASCIIColors.execute_with_animation("Loading loacal STT services", start_stt, ASCIIColors.color_blue)
ASCIIColors.blue("Activating STT service")
if self.config.active_stt_service == "openai_whisper" and (self.tts is None or self.tts.name!="openai_whisper"):
from lollms.services.stt.openai_whisper.lollms_openai_whisper import LollmsOpenAIWhisper
self.stt = LollmsOpenAIWhisper(self)
elif self.config.active_stt_service == "whisper" and (self.tts is None or self.tts.name!="whisper") :
from lollms.services.stt.whisper.lollms_whisper import LollmsWhisper
self.stt = LollmsWhisper(self)
def start_tts(*args, **kwargs):
self.tts = self.load_service_from_folder(self.lollms_paths.services_zoo_path/"tts", self.config.active_tts_service)
ASCIIColors.execute_with_animation("Loading loacal STT services", start_tts, ASCIIColors.color_blue)
def start_ttv(*args, **kwargs):

View File

@ -18,8 +18,8 @@ from lollms.utilities import find_next_available_filename, output_file_path_to_u
from lollms.security import sanitize_path, validate_path, check_access
from pathlib import Path
from ascii_colors import ASCIIColors
import os
import platform
from typing import List, Dict
import yaml
# ----------------------- Defining router and main class ------------------------------
@ -62,34 +62,60 @@ async def audio2text(request: LollmsAudio2TextRequest):
@router.post("/list_stt_services")
async def list_stt_services(request: ServiceListingRequest):
async def list_stt_services(request: ServiceListingRequest) -> List[Dict[str, str]]:
"""
Dumb endpoint that returns a static list of STT services.
Endpoint that returns a list of STT services by scanning subfolders in services_zoo_path.
Args:
request (ServiceListingRequest): The request body containing the client_id.
Returns:
List[str]: A list of STT service names.
List[Dict[str, str]]: A list of STT service dictionaries containing name, caption, and help.
"""
# Validate the client_id (dumb validation for demonstration)
# Validate the client_id
check_access(lollmsElfServer, request.client_id)
# Get the services directory path
services_path = lollmsElfServer.lollms_paths.services_zoo_path/"stt"
# Static list of STT services
stt_services = [
{"name": "whisper", "caption":"Whisper", "help":"Whisper local speech to text service"},
{"name": "openai_whisper", "caption":"Open AI Whisper STT", "help":"Open ai remote speech to text service"},
]
# Initialize empty list for services
stt_services = []
# Check if the directory exists
if not services_path.exists() or not services_path.is_dir():
return stt_services # Return empty list if directory doesn't exist
# Iterate through subfolders
for service_folder in services_path.iterdir():
if service_folder.is_dir() and service_folder.stem not in [".git", ".vscode"]:
# Look for config.yaml in each subfolder
config_file = service_folder / "config.yaml"
if config_file.exists():
try:
# Read and parse the YAML file
with open(config_file, 'r') as f:
config = yaml.safe_load(f)
# Build service dictionary
service_info = {
"name": service_folder.name,
"caption": config.get("caption", service_folder.name),
"help": config.get("help", f"{service_folder.name} text to image services")
}
stt_services.append(service_info)
except Exception as e:
# Log error if needed, skip invalid config files
continue
return stt_services
@router.post("/get_active_stt_settings")
async def get_active_stt_settings(request: Request):
@router.post("/get_active_stt_sesttngs")
async def get_active_stt_sesttngs(request: Request):
data = await request.json()
check_access(lollmsElfServer,data["client_id"])
print("- Retreiving stt settings")
print("- Retreiving stt sesttngs")
if lollmsElfServer.stt is not None:
if hasattr(lollmsElfServer.stt,"service_config"):
return lollmsElfServer.stt.service_config.config_template.template
@ -98,26 +124,26 @@ async def get_active_stt_settings(request: Request):
else:
return {}
@router.post("/set_active_stt_settings")
async def set_active_stt_settings(request: Request):
@router.post("/set_active_stt_sesttngs")
async def set_active_stt_sesttngs(request: Request):
data = await request.json()
check_access(lollmsElfServer,data["client_id"])
settings = data["settings"]
sesttngs = data["sesttngs"]
"""
Sets the active stt settings.
Sets the active stt sesttngs.
:param request: The sttSettingsRequest object.
:param request: The sttSesttngsRequest object.
:return: A JSON response with the status of the operation.
"""
try:
print("- Setting stt settings")
print("- Sesttng stt sesttngs")
if lollmsElfServer.stt is not None:
if hasattr(lollmsElfServer.stt,"service_config"):
lollmsElfServer.stt.service_config.update_template(settings)
lollmsElfServer.stt.service_config.update_template(sesttngs)
lollmsElfServer.stt.service_config.config.save_config()
lollmsElfServer.stt.settings_updated()
lollmsElfServer.stt.sesttngs_updated()
return {'status':True}
else:
return {'status':False}