Spaces:
Paused
Paused
File size: 1,898 Bytes
dff1e71 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import asyncio
from python.helpers import runtime, whisper, settings
from python.helpers.print_style import PrintStyle
from python.helpers import kokoro_tts
import models
async def preload():
try:
set = settings.get_default_settings()
# preload whisper model
async def preload_whisper():
try:
return await whisper.preload(set["stt_model_size"])
except Exception as e:
PrintStyle().error(f"Error in preload_whisper: {e}")
# preload embedding model
async def preload_embedding():
if set["embed_model_provider"].lower() == "huggingface":
try:
# Use the new LiteLLM-based model system
emb_mod = models.get_embedding_model(
"huggingface", set["embed_model_name"]
)
emb_txt = await emb_mod.aembed_query("test")
return emb_txt
except Exception as e:
PrintStyle().error(f"Error in preload_embedding: {e}")
# preload kokoro tts model if enabled
async def preload_kokoro():
if set["tts_kokoro"]:
try:
return await kokoro_tts.preload()
except Exception as e:
PrintStyle().error(f"Error in preload_kokoro: {e}")
# async tasks to preload
tasks = [
preload_embedding(),
# preload_whisper(),
# preload_kokoro()
]
await asyncio.gather(*tasks, return_exceptions=True)
PrintStyle().print("Preload completed")
except Exception as e:
PrintStyle().error(f"Error in preload: {e}")
# preload transcription model
if __name__ == "__main__":
PrintStyle().print("Running preload...")
runtime.initialize()
asyncio.run(preload())
|