Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,11 +39,11 @@ theme = gr.themes.Monochrome(
|
|
| 39 |
button_primary_background_fill_hover='*neutral_100'
|
| 40 |
)
|
| 41 |
|
| 42 |
-
#STEP 1 FROM
|
| 43 |
from sentence_transformers import SentenceTransformer
|
| 44 |
import torch
|
| 45 |
|
| 46 |
-
#STEP 2 FROM
|
| 47 |
# Open the weather.txt file in read mode with UTF-8 encoding
|
| 48 |
with open("weather.txt", "r", encoding="utf-8") as file:
|
| 49 |
# Read the entire contents of the file and store it in a variable
|
|
@@ -58,7 +58,7 @@ with open("food.txt", "r", encoding="utf-8") as file:
|
|
| 58 |
# Read the entire contents of the file and store it in a variable
|
| 59 |
food_text = file.read()
|
| 60 |
|
| 61 |
-
#STEP 3 FROM
|
| 62 |
def preprocess_text(text):
|
| 63 |
# Strip extra whitespace from the beginning and the end of the text
|
| 64 |
cleaned_text = text.strip()
|
|
@@ -79,7 +79,7 @@ cleaned_chunks_luggage = preprocess_text(luggage_text)
|
|
| 79 |
cleaned_chunks_attraction = preprocess_text(attraction_text)
|
| 80 |
cleaned_chunks_food = preprocess_text(food_text)
|
| 81 |
|
| 82 |
-
#STEP 4 FROM
|
| 83 |
# Load the pre-trained embedding model that converts text to vectors
|
| 84 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 85 |
|
|
@@ -94,7 +94,7 @@ chunk_embeddings_luggage = create_embeddings(cleaned_chunks_luggage)
|
|
| 94 |
chunk_embeddings_attraction = create_embeddings(cleaned_chunks_attraction)
|
| 95 |
chunk_embeddings_food = create_embeddings(cleaned_chunks_food)
|
| 96 |
|
| 97 |
-
#STEP 5 FROM
|
| 98 |
# Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
|
| 99 |
def get_top_chunks(query, chunk_embeddings, text_chunks):
|
| 100 |
# Convert the query text into a vector embedding
|
|
|
|
| 39 |
button_primary_background_fill_hover='*neutral_100'
|
| 40 |
)
|
| 41 |
|
| 42 |
+
#STEP 1 FROM SEMANTIC SEARCH
|
| 43 |
from sentence_transformers import SentenceTransformer
|
| 44 |
import torch
|
| 45 |
|
| 46 |
+
#STEP 2 FROM SEMANTIC SEARCH
|
| 47 |
# Open the weather.txt file in read mode with UTF-8 encoding
|
| 48 |
with open("weather.txt", "r", encoding="utf-8") as file:
|
| 49 |
# Read the entire contents of the file and store it in a variable
|
|
|
|
| 58 |
# Read the entire contents of the file and store it in a variable
|
| 59 |
food_text = file.read()
|
| 60 |
|
| 61 |
+
#STEP 3 FROM SEMANTIC SEARCH
|
| 62 |
def preprocess_text(text):
|
| 63 |
# Strip extra whitespace from the beginning and the end of the text
|
| 64 |
cleaned_text = text.strip()
|
|
|
|
| 79 |
cleaned_chunks_attraction = preprocess_text(attraction_text)
|
| 80 |
cleaned_chunks_food = preprocess_text(food_text)
|
| 81 |
|
| 82 |
+
#STEP 4 FROM SEMANTIC SEARCH
|
| 83 |
# Load the pre-trained embedding model that converts text to vectors
|
| 84 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 85 |
|
|
|
|
| 94 |
chunk_embeddings_attraction = create_embeddings(cleaned_chunks_attraction)
|
| 95 |
chunk_embeddings_food = create_embeddings(cleaned_chunks_food)
|
| 96 |
|
| 97 |
+
#STEP 5 FROM SEMANTIC SEARCH
|
| 98 |
# Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
|
| 99 |
def get_top_chunks(query, chunk_embeddings, text_chunks):
|
| 100 |
# Convert the query text into a vector embedding
|