Spaces:
Running
Running
File size: 1,347 Bytes
1005046 |
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 |
import os
import time
import nltk
from app.services.chatbot import build_chat_fn
from app.core.config import (
NLTK_PATH,
QDRANT_API_KEY,
QDRANT_ENDPOINT,
QDRANT_MOVIE_COLLECTION_NAME,
QDRANT_TV_COLLECTION_NAME,
)
from app.llm.custom_models import load_sentence_model, load_bm25_files, setup_intent_classifier
from app.retrieval.retriever import get_media_retriever
from app.retrieval.vectorstore import connect_qdrant
start = time.time()
os.environ["TOKENIZERS_PARALLELISM"] = "false"
# nltk.data.path.append(str(NLTK_PATH))
def setup_retriever():
embed_model = load_sentence_model()
bm25_models, bm25_vocabs = load_bm25_files()
nltk.data.path.append(str(NLTK_PATH))
print("✅ NLTK resources loaded")
qdrant_client = connect_qdrant(endpoint=QDRANT_ENDPOINT, api_key=QDRANT_API_KEY)
return get_media_retriever(
embed_model=embed_model,
qdrant_client=qdrant_client,
bm25_models=bm25_models,
bm25_vocabs=bm25_vocabs,
movie_collection_name=QDRANT_MOVIE_COLLECTION_NAME,
tv_collection_name=QDRANT_TV_COLLECTION_NAME,
)
# Initialize once at startup
retriever = setup_retriever()
intent_classifier = setup_intent_classifier()
chat_fn = build_chat_fn(retriever, intent_classifier)
print(f"🔧 Total startup time: {time.time() - start:.2f}s")
|