Update functions.py
Browse files- functions.py +16 -7
functions.py
CHANGED
@@ -151,14 +151,12 @@ def process_corpus(corpus, tok, title, embeddings, chunk_size=200, overlap=50):
|
|
151 |
)
|
152 |
|
153 |
return docsearch
|
154 |
-
|
155 |
-
@st.experimental_memo(suppress_st_warning=True)
|
156 |
-
def embed_text(query,corpus,title,embedding_model,emb_tok,chain_type='stuff'):
|
157 |
-
|
158 |
-
'''Embed text and generate semantic search scores'''
|
159 |
|
160 |
-
|
|
|
161 |
|
|
|
|
|
162 |
if 'hkunlp' in embedding_model:
|
163 |
|
164 |
embeddings = HuggingFaceInstructEmbeddings(model_name=f'hkunlp/{embedding_model}',
|
@@ -167,7 +165,18 @@ def embed_text(query,corpus,title,embedding_model,emb_tok,chain_type='stuff'):
|
|
167 |
|
168 |
else:
|
169 |
|
170 |
-
embeddings = HuggingFaceEmbeddings(model_name=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
title = title[0]
|
173 |
docsearch = process_corpus(corpus,embed_tok,title, embeddings)
|
|
|
151 |
)
|
152 |
|
153 |
return docsearch
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
+
@st.experimental_singleton(suppress_st_warning=True)
|
156 |
+
def gen_embeddings(embedding_model):
|
157 |
|
158 |
+
'''Generate embeddings for given model'''
|
159 |
+
|
160 |
if 'hkunlp' in embedding_model:
|
161 |
|
162 |
embeddings = HuggingFaceInstructEmbeddings(model_name=f'hkunlp/{embedding_model}',
|
|
|
165 |
|
166 |
else:
|
167 |
|
168 |
+
embeddings = HuggingFaceEmbeddings(model_name=embedding_model)
|
169 |
+
|
170 |
+
return embeddings
|
171 |
+
|
172 |
+
@st.experimental_memo(suppress_st_warning=True)
|
173 |
+
def embed_text(query,corpus,title,embedding_model,emb_tok,chain_type='stuff'):
|
174 |
+
|
175 |
+
'''Embed text and generate semantic search scores'''
|
176 |
+
|
177 |
+
index_id = "earnings-embeddings"
|
178 |
+
|
179 |
+
embeddings = gen_embeddings(embedding_model)
|
180 |
|
181 |
title = title[0]
|
182 |
docsearch = process_corpus(corpus,embed_tok,title, embeddings)
|