forked from agent0ai/agent-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.py
More file actions
42 lines (32 loc) · 1.32 KB
/
preload.py
File metadata and controls
42 lines (32 loc) · 1.32 KB
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
import asyncio
from python.helpers import runtime, whisper, settings
from python.helpers.print_style import PrintStyle
import models
PrintStyle().print("Running preload...")
runtime.initialize()
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"] == models.ModelProvider.HUGGINGFACE.name:
try:
emb_mod = models.get_huggingface_embedding(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}")
# async tasks to preload
tasks = [preload_whisper(), preload_embedding()]
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
asyncio.run(preload())