Amirizaniani commited on
Commit
fe00f69
1 Parent(s): 1c13787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -42,7 +42,6 @@ def answer_question(prompt):
42
  generated_answer = hub_chain.run(input_data)
43
  return generated_answer
44
 
45
-
46
  def calculate_similarity(word, other_words, model, threshold=0.5):
47
  embeddings_word = model.encode([word])
48
  embeddings_other_words = model.encode(other_words)
@@ -106,7 +105,7 @@ def highlight_words_within_cluster(sentences, model, exclude_words):
106
 
107
  exclude_words = {"a", "the", "for", "from", "of", "in","over", "as", "on", "is", "am", "have", "an","has", "had", "and", "by", "it", "its", "those", "these", "was", "were", "their", "them", "I", "you", "also", "your", "me", "after"}
108
 
109
- def cluster_sentences(sentences, model, num_clusters=1):
110
  embeddings = model.encode(sentences)
111
  kmeans = KMeans(n_clusters=num_clusters)
112
  kmeans.fit(embeddings)
@@ -123,6 +122,8 @@ sentences = ["In a quaint little town nestled in the heart of the mountains, a s
123
 
124
  "In a cozy, mountain-encircled village, a beloved bakery was the center of attraction, known for its traditional baking methods and delightful pastries, drawing a consistent stream of people waiting outside, all desiring to experience the renowned flavors that made the bakery's products distinctively mouth-watering."]
125
 
 
 
126
  sentence_clusters = cluster_sentences(sentences, model, num_clusters)
127
 
128
  # Step 2: Highlight similar words within each cluster
@@ -133,7 +134,7 @@ for sentence, cluster_id in zip(sentences, sentence_clusters):
133
  highlighted_clustered_sentences = []
134
  for cluster in clustered_sentences:
135
  highlighted_clustered_sentences.extend(highlight_words_within_cluster(cluster, model, exclude_words))
136
-
137
 
138
  text_list = []
139
 
 
42
  generated_answer = hub_chain.run(input_data)
43
  return generated_answer
44
 
 
45
  def calculate_similarity(word, other_words, model, threshold=0.5):
46
  embeddings_word = model.encode([word])
47
  embeddings_other_words = model.encode(other_words)
 
105
 
106
  exclude_words = {"a", "the", "for", "from", "of", "in","over", "as", "on", "is", "am", "have", "an","has", "had", "and", "by", "it", "its", "those", "these", "was", "were", "their", "them", "I", "you", "also", "your", "me", "after"}
107
 
108
+ def cluster_sentences(sentences, model, num_clusters=3):
109
  embeddings = model.encode(sentences)
110
  kmeans = KMeans(n_clusters=num_clusters)
111
  kmeans.fit(embeddings)
 
122
 
123
  "In a cozy, mountain-encircled village, a beloved bakery was the center of attraction, known for its traditional baking methods and delightful pastries, drawing a consistent stream of people waiting outside, all desiring to experience the renowned flavors that made the bakery's products distinctively mouth-watering."]
124
 
125
+ # Step 1: Cluster the sentences
126
+ num_clusters = 1
127
  sentence_clusters = cluster_sentences(sentences, model, num_clusters)
128
 
129
  # Step 2: Highlight similar words within each cluster
 
134
  highlighted_clustered_sentences = []
135
  for cluster in clustered_sentences:
136
  highlighted_clustered_sentences.extend(highlight_words_within_cluster(cluster, model, exclude_words))
137
+
138
 
139
  text_list = []
140