Spaces:
Sleeping
Sleeping
update to travel_info.txt
Browse files
app.py
CHANGED
|
@@ -6,8 +6,8 @@ from sentence_transformers import SentenceTransformer
|
|
| 6 |
import torch
|
| 7 |
|
| 8 |
#STEP 2 FROM SEMANTIC SEARCH
|
| 9 |
-
with open("
|
| 10 |
-
|
| 11 |
|
| 12 |
#STEP 3 FROM SEMANTIC SEARCH
|
| 13 |
def preprocess_text(text):
|
|
@@ -25,7 +25,7 @@ def preprocess_text(text):
|
|
| 25 |
|
| 26 |
return cleaned_chunks
|
| 27 |
|
| 28 |
-
cleaned_chunks = preprocess_text(
|
| 29 |
|
| 30 |
#STEP 4 FROM SEMANTIC SEARCH
|
| 31 |
model = SentenceTransformer('all-MiniLM-L6-v2') # Load pre-trained embedding model that converts text to vectors
|
|
@@ -62,7 +62,7 @@ def get_top_chunks(query, chunk_embeddings, text_chunks): #Finds most relevant t
|
|
| 62 |
return top_chunks
|
| 63 |
|
| 64 |
#STEP 6 FROM SEMANTIC SEARCH
|
| 65 |
-
top_results = get_top_chunks("
|
| 66 |
print(top_results)
|
| 67 |
|
| 68 |
#SAMPLE HUGGING FACE PROJECT
|
|
|
|
| 6 |
import torch
|
| 7 |
|
| 8 |
#STEP 2 FROM SEMANTIC SEARCH
|
| 9 |
+
with open("travel_info.txt", "r", encoding="utf-8") as file: # Open the travel_info.txt file in read mode with UTF-8 encoding
|
| 10 |
+
travel_text = file.read() # Read file and store into variable
|
| 11 |
|
| 12 |
#STEP 3 FROM SEMANTIC SEARCH
|
| 13 |
def preprocess_text(text):
|
|
|
|
| 25 |
|
| 26 |
return cleaned_chunks
|
| 27 |
|
| 28 |
+
cleaned_chunks = preprocess_text(travel_text) # Call preprocess_text and store result in cleaned_chunks
|
| 29 |
|
| 30 |
#STEP 4 FROM SEMANTIC SEARCH
|
| 31 |
model = SentenceTransformer('all-MiniLM-L6-v2') # Load pre-trained embedding model that converts text to vectors
|
|
|
|
| 62 |
return top_chunks
|
| 63 |
|
| 64 |
#STEP 6 FROM SEMANTIC SEARCH
|
| 65 |
+
top_results = get_top_chunks("Why is it important to carry copies of your travel documents?", chunk_embeddings, cleaned_chunks) # Call get_top_chunks with query
|
| 66 |
print(top_results)
|
| 67 |
|
| 68 |
#SAMPLE HUGGING FACE PROJECT
|