fionasu commited on
Commit
b765f56
·
verified ·
1 Parent(s): ad41c44

added food and attractions

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -13,6 +13,12 @@ with open("weather.txt", "r", encoding="utf-8") as file:
13
  with open("luggage.txt", "r", encoding="utf-8") as file:
14
  # Read the entire contents of the file and store it in a variable
15
  luggage_text = file.read()
 
 
 
 
 
 
16
 
17
  #STEP 3 FROM SEMATIC SEARCH
18
  def preprocess_text(text):
@@ -37,6 +43,8 @@ def preprocess_text(text):
37
  # Call the preprocess_text function and store the result in a cleaned_chunks variable
38
  cleaned_chunks_weather = preprocess_text(weather_text) # Complete this line
39
  cleaned_chunks_luggage = preprocess_text(luggage_text)
 
 
40
 
41
  #STEP 4 FROM SEMATIC SEARCH
42
  # Load the pre-trained embedding model that converts text to vectors
@@ -55,6 +63,8 @@ def create_embeddings(text_chunks):
55
  # Call the create_embeddings function and store the result in a new chunk_embeddings variable
56
  chunk_embeddings_weather = create_embeddings(cleaned_chunks_weather) # Complete this line
57
  chunk_embeddings_luggage = create_embeddings(cleaned_chunks_luggage)
 
 
58
 
59
  #STEP 5 FROM SEMATIC SEARCH
60
  # Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
@@ -93,11 +103,17 @@ client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
93
  def respond(message, history,use_spanish, destinations, season, luggage_types, luggage_size, food_prefs):
94
  top_weather = get_top_chunks(message, chunk_embeddings_weather, cleaned_chunks_weather)
95
  top_luggage = get_top_chunks(message, chunk_embeddings_luggage, cleaned_chunks_luggage)
 
 
96
  print(top_weather)
97
  print(top_luggage)
 
 
98
 
99
  str_top_weather = "\n".join(top_weather)
100
  str_top_luggage = "\n".join(top_luggage)
 
 
101
 
102
  lang = "Spanish" if use_spanish else "English"
103
  ctx = (
@@ -107,7 +123,7 @@ def respond(message, history,use_spanish, destinations, season, luggage_types, l
107
  f"Luggage: {', '.join(luggage_types)} of size {luggage_size}\n"
108
  f"Food: {', '.join(food_prefs)}\n"
109
  )
110
-
111
  messages = [{"role": "system", "content": f"You're a friendly and gen z chatbot. Base your response on the provided context: {top_weather} and {top_luggage}."}]
112
 
113
  if history:
 
13
  with open("luggage.txt", "r", encoding="utf-8") as file:
14
  # Read the entire contents of the file and store it in a variable
15
  luggage_text = file.read()
16
+ with open("attraction.txt", "r", encoding="utf-8") as file:
17
+ # Read the entire contents of the file and store it in a variable
18
+ attraction_text = file.read()
19
+ with open("food.txt", "r", encoding="utf-8") as file:
20
+ # Read the entire contents of the file and store it in a variable
21
+ food_text = file.read()
22
 
23
  #STEP 3 FROM SEMATIC SEARCH
24
  def preprocess_text(text):
 
43
  # Call the preprocess_text function and store the result in a cleaned_chunks variable
44
  cleaned_chunks_weather = preprocess_text(weather_text) # Complete this line
45
  cleaned_chunks_luggage = preprocess_text(luggage_text)
46
+ cleaned_chunks_attraction = preprocess_text(attraction_text)
47
+ cleaned_chunks_food = preprocess_text(food_text)
48
 
49
  #STEP 4 FROM SEMATIC SEARCH
50
  # Load the pre-trained embedding model that converts text to vectors
 
63
  # Call the create_embeddings function and store the result in a new chunk_embeddings variable
64
  chunk_embeddings_weather = create_embeddings(cleaned_chunks_weather) # Complete this line
65
  chunk_embeddings_luggage = create_embeddings(cleaned_chunks_luggage)
66
+ chunk_embeddings_attraction = create_embeddings(cleaned_chunks_attraction)
67
+ chunk_embeddings_food = create_embeddings(cleaned_chunks_food)
68
 
69
  #STEP 5 FROM SEMATIC SEARCH
70
  # Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
 
103
  def respond(message, history,use_spanish, destinations, season, luggage_types, luggage_size, food_prefs):
104
  top_weather = get_top_chunks(message, chunk_embeddings_weather, cleaned_chunks_weather)
105
  top_luggage = get_top_chunks(message, chunk_embeddings_luggage, cleaned_chunks_luggage)
106
+ top_attraction = get_top_chunks(message, chunk_embeddings_attraction, cleaned_chunks_attraction)
107
+ top_food = get_top_chunks(message, chunk_embeddings_food, cleaned_chunks_food)
108
  print(top_weather)
109
  print(top_luggage)
110
+ print(top_attraction)
111
+ print(top_food)
112
 
113
  str_top_weather = "\n".join(top_weather)
114
  str_top_luggage = "\n".join(top_luggage)
115
+ str_top_attraction = "\n".join(top_attraction)
116
+ str_top_food = "\n".join(top_food)
117
 
118
  lang = "Spanish" if use_spanish else "English"
119
  ctx = (
 
123
  f"Luggage: {', '.join(luggage_types)} of size {luggage_size}\n"
124
  f"Food: {', '.join(food_prefs)}\n"
125
  )
126
+
127
  messages = [{"role": "system", "content": f"You're a friendly and gen z chatbot. Base your response on the provided context: {top_weather} and {top_luggage}."}]
128
 
129
  if history: