Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -45,19 +45,28 @@ def setTextVisibility(cbg, model_name_input):
|
|
45 |
sentences = []
|
46 |
result = []
|
47 |
model = SentenceTransformer('all-mpnet-base-v2')
|
48 |
-
exclude_words = {"a", "the", "for", "from", "of", "in", "over", "as", "on", "is", "am", "have", "an", "has", "had", "and", "by", "it", "its", "those", "these", "above", "to"
|
49 |
sentences_org = ["In a quaint little town nestled in the heart of the mountains, a small bakery famous for its artisanal breads and pastries had a line of customers stretching out the door, eagerly waiting to savor the freshly baked goods that were known far and wide for their delightful flavors.",
|
50 |
"Within a picturesque mountain village, there stood a renowned bakery, celebrated for its handcrafted bread and sweet treats, attracting a long queue of patrons each morning, all keen to enjoy the baked delicacies that had gained widespread acclaim for their exceptional taste.",
|
51 |
"A charming bakery, located in a small mountainous hamlet, renowned for producing exquisite handmade pastries and bread, was bustling with a crowd of eager customers lined up outside, each anticipating the chance to indulge in the famous baked items celebrated for their extraordinary deliciousness.",
|
52 |
"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."]
|
53 |
for text in cbg:
|
54 |
sentences.append(answer_question(text, model_name_input))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
other_sentences = sentences[:i] + sentences[i+1:]
|
59 |
-
highlighted_sentence = highlight_words(sentence, other_sentences, model, exclude_words)
|
60 |
-
highlighted_sentences.append(highlighted_sentence)
|
61 |
|
62 |
for idx, sentence in enumerate(highlighted_sentences):
|
63 |
result.append("<p><strong>"+ cbg[idx] +"</strong></p><p>"+ sentence +"</p><br/>")
|
|
|
45 |
sentences = []
|
46 |
result = []
|
47 |
model = SentenceTransformer('all-mpnet-base-v2')
|
48 |
+
exclude_words = {"a", "the", "for", "from", "of", "in", "over", "as", "on", "is", "am", "have", "an", "has", "had", "and", "by", "it", "its", "those", "these", "above", "to"}
|
49 |
sentences_org = ["In a quaint little town nestled in the heart of the mountains, a small bakery famous for its artisanal breads and pastries had a line of customers stretching out the door, eagerly waiting to savor the freshly baked goods that were known far and wide for their delightful flavors.",
|
50 |
"Within a picturesque mountain village, there stood a renowned bakery, celebrated for its handcrafted bread and sweet treats, attracting a long queue of patrons each morning, all keen to enjoy the baked delicacies that had gained widespread acclaim for their exceptional taste.",
|
51 |
"A charming bakery, located in a small mountainous hamlet, renowned for producing exquisite handmade pastries and bread, was bustling with a crowd of eager customers lined up outside, each anticipating the chance to indulge in the famous baked items celebrated for their extraordinary deliciousness.",
|
52 |
"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."]
|
53 |
for text in cbg:
|
54 |
sentences.append(answer_question(text, model_name_input))
|
55 |
+
|
56 |
+
# Step 1: Cluster the sentences
|
57 |
+
num_clusters = 1
|
58 |
+
sentence_clusters = cluster_sentences(sentences, model, num_clusters)
|
59 |
+
|
60 |
+
# Step 2: Highlight similar words within each cluster
|
61 |
+
clustered_sentences = [[] for _ in range(num_clusters)]
|
62 |
+
|
63 |
+
for sentence, cluster_id in zip(sentences, sentence_clusters):
|
64 |
+
clustered_sentences[cluster_id].append(sentence)
|
65 |
+
|
66 |
+
highlighted_clustered_sentences = []
|
67 |
|
68 |
+
for cluster in clustered_sentences:
|
69 |
+
highlighted_clustered_sentences.extend(highlight_words_within_cluster(cluster, model, exclude_words))
|
|
|
|
|
|
|
70 |
|
71 |
for idx, sentence in enumerate(highlighted_sentences):
|
72 |
result.append("<p><strong>"+ cbg[idx] +"</strong></p><p>"+ sentence +"</p><br/>")
|