Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,9 +20,9 @@ def preprocess_text(text):
|
|
| 20 |
cleaned_chunks.append(stripped_chunk)
|
| 21 |
|
| 22 |
|
| 23 |
-
print(cleaned_chunks)
|
| 24 |
|
| 25 |
-
print (len(cleaned_chunks))
|
| 26 |
|
| 27 |
return cleaned_chunks
|
| 28 |
|
|
@@ -31,9 +31,9 @@ model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
| 31 |
def create_embeddings(text_chunks):
|
| 32 |
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True) # Replace ... with the text_chunks list
|
| 33 |
|
| 34 |
-
print(chunk_embeddings)
|
| 35 |
|
| 36 |
-
print(chunk_embeddings.shape)
|
| 37 |
|
| 38 |
return chunk_embeddings
|
| 39 |
|
|
@@ -48,11 +48,11 @@ def get_top_chunks(query, chunk_embeddings, text_chunks):
|
|
| 48 |
|
| 49 |
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized) # Complete this line
|
| 50 |
|
| 51 |
-
print(similarities)
|
| 52 |
|
| 53 |
top_indices = torch.topk(similarities, k=3).indices
|
| 54 |
|
| 55 |
-
print(top_indices)
|
| 56 |
|
| 57 |
top_chunks = []
|
| 58 |
|
|
@@ -64,7 +64,7 @@ def get_top_chunks(query, chunk_embeddings, text_chunks):
|
|
| 64 |
|
| 65 |
top_results = get_top_chunks("Your account has been compromised", chunk_embeddings, cleaned_chunks) # Complete this line
|
| 66 |
|
| 67 |
-
print(top_results)
|
| 68 |
|
| 69 |
|
| 70 |
cleaned_chunks = preprocess_text(knowledge_base)
|
|
|
|
| 20 |
cleaned_chunks.append(stripped_chunk)
|
| 21 |
|
| 22 |
|
| 23 |
+
#print(cleaned_chunks)
|
| 24 |
|
| 25 |
+
#print (len(cleaned_chunks))
|
| 26 |
|
| 27 |
return cleaned_chunks
|
| 28 |
|
|
|
|
| 31 |
def create_embeddings(text_chunks):
|
| 32 |
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True) # Replace ... with the text_chunks list
|
| 33 |
|
| 34 |
+
#print(chunk_embeddings)
|
| 35 |
|
| 36 |
+
#print(chunk_embeddings.shape)
|
| 37 |
|
| 38 |
return chunk_embeddings
|
| 39 |
|
|
|
|
| 48 |
|
| 49 |
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized) # Complete this line
|
| 50 |
|
| 51 |
+
#print(similarities)
|
| 52 |
|
| 53 |
top_indices = torch.topk(similarities, k=3).indices
|
| 54 |
|
| 55 |
+
#print(top_indices)
|
| 56 |
|
| 57 |
top_chunks = []
|
| 58 |
|
|
|
|
| 64 |
|
| 65 |
top_results = get_top_chunks("Your account has been compromised", chunk_embeddings, cleaned_chunks) # Complete this line
|
| 66 |
|
| 67 |
+
#print(top_results)
|
| 68 |
|
| 69 |
|
| 70 |
cleaned_chunks = preprocess_text(knowledge_base)
|