Spaces:
Sleeping
Sleeping
Update question_handler.py
Browse files- question_handler.py +6 -0
question_handler.py
CHANGED
|
@@ -1,5 +1,11 @@
|
|
| 1 |
import re
|
| 2 |
from sklearn.metrics.pairwise import cosine_similarity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def find_top_question(query, metadata, embeddings):
|
| 5 |
query_embedding = model.encode(query, convert_to_tensor=True).cpu().numpy().reshape(1, -1)
|
|
|
|
| 1 |
import re
|
| 2 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 3 |
+
from embeddings_utils import load_model
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Load the SentenceTransformer model directly in this file
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
model = load_model(device)
|
| 9 |
|
| 10 |
def find_top_question(query, metadata, embeddings):
|
| 11 |
query_embedding = model.encode(query, convert_to_tensor=True).cpu().numpy().reshape(1, -1)
|