Spaces:
Runtime error
Runtime error
Commit
·
a15d048
1
Parent(s):
d99b030
Update app.py
Browse files
app.py
CHANGED
@@ -93,21 +93,22 @@ class SemanticSearch:
|
|
93 |
embeddings.append(emb_batch)
|
94 |
embeddings = np.vstack(embeddings)
|
95 |
return embeddings'''
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
111 |
|
112 |
|
113 |
def load_recommender(path, start_page=1):
|
|
|
93 |
embeddings.append(emb_batch)
|
94 |
embeddings = np.vstack(embeddings)
|
95 |
return embeddings'''
|
96 |
+
|
97 |
+
def get_text_embedding(self, texts):
|
98 |
+
embeddings = []
|
99 |
+
if isinstance(self.embedder, openai.Engine):
|
100 |
+
for text in texts:
|
101 |
+
response = self.embedder.search(
|
102 |
+
documents=texts,
|
103 |
+
query=text,
|
104 |
+
max_rerank=1
|
105 |
+
)
|
106 |
+
embeddings.append(response["data"][0]["score"])
|
107 |
+
elif isinstance(self.embedder, hub.Module):
|
108 |
+
embeddings = self.embedder(texts)
|
109 |
+
else:
|
110 |
+
raise ValueError("Invalid embedder.")
|
111 |
+
return np.array(embeddings)
|
112 |
|
113 |
|
114 |
def load_recommender(path, start_page=1):
|