amburp commited on
Commit
b8d8ab4
·
verified ·
1 Parent(s): 8615286

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -13,10 +13,9 @@ def preprocess_text(text):
13
  cleaned_chunks = []
14
 
15
  for chunk in chunks:
16
- chunk.strip()
17
-
18
- if chunk != "":
19
- cleaned_chunks.append(chunk)
20
 
21
  return cleaned_chunks
22
  cleaned_chunks = preprocess_text(info_text)
@@ -24,10 +23,11 @@ cleaned_chunks = preprocess_text(info_text)
24
  # Load the pre-trained embedding model that converts text to vectors
25
  model = SentenceTransformer('all-MiniLM-L6-v2')
26
 
 
 
27
  def create_embeddings(text_chunks):
28
- chunk_embeddings = model.encode(cleaned_chunks, convert_to_tensor=True) # Replace ... with the text_chunks list
29
  return chunk_embeddings
30
- chunk_embeddings = create_embeddings(cleaned_chunks) # Complete this line
31
 
32
  # Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
33
  def get_top_chunks(query, chunk_embeddings, text_chunks):
@@ -47,13 +47,22 @@ def query_model(question):
47
  """
48
  Process a question, find relevant information, and generate a response.
49
  """
50
- if question == "":
51
  return "Welcome to GreenGuide! Ask me anything about eco-friendly hotels, restaurants, and things to do in NYC."
52
- relevant_segment = find_relevant_segment(question, segments)
53
- if not relevant_segment:
54
- return "Could not find specific information. Please refine your question."
55
- response = generate_response(question, relevant_segment)
 
 
 
56
  return response
 
 
 
 
 
 
57
 
58
 
59
  def display_iframe():
 
13
  cleaned_chunks = []
14
 
15
  for chunk in chunks:
16
+ chunk = chunk.strip()
17
+ if chunk != "":
18
+ cleaned_chunks:append(chunk)
 
19
 
20
  return cleaned_chunks
21
  cleaned_chunks = preprocess_text(info_text)
 
23
  # Load the pre-trained embedding model that converts text to vectors
24
  model = SentenceTransformer('all-MiniLM-L6-v2')
25
 
26
+ chunk_embeddings = create_embeddings(cleaned_chunks) # Complete this line
27
+
28
  def create_embeddings(text_chunks):
29
+ chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True) # Replace ... with the text_chunks list
30
  return chunk_embeddings
 
31
 
32
  # Define a function to find the most relevant text chunks for a given query, chunk_embeddings, and text_chunks
33
  def get_top_chunks(query, chunk_embeddings, text_chunks):
 
47
  """
48
  Process a question, find relevant information, and generate a response.
49
  """
50
+ if question.strip() == "":
51
  return "Welcome to GreenGuide! Ask me anything about eco-friendly hotels, restaurants, and things to do in NYC."
52
+
53
+ top_chunks = get_top_chunks(question, chunk_embeddings, cleaned_chunks)
54
+
55
+ response = "Here are the most relevant results:\n\n"
56
+ for i, chunk in enumerate(top_chunks, start=1):
57
+ response += f"{i}. {chunk}\n\n"
58
+
59
  return response
60
+
61
+ # relevant_segment = find_relevant_segment(question, segments)
62
+ # if not relevant_segment:
63
+ # return "Could not find specific information. Please refine your question."
64
+ # response = generate_response(question, relevant_segment)
65
+ # return response
66
 
67
 
68
  def display_iframe():