awacke1 commited on
Commit
0718e3a
1 Parent(s): 6556590

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -108,10 +108,16 @@ def load_example_files():
108
 
109
  return None
110
 
 
111
  def cluster_sentences(sentences, num_clusters):
112
  # Filter sentences with length over 10 characters
113
  sentences = [sentence for sentence in sentences if len(sentence) > 10]
114
 
 
 
 
 
 
115
  # Vectorize the sentences
116
  vectorizer = TfidfVectorizer()
117
  X = vectorizer.fit_transform(sentences)
@@ -136,6 +142,7 @@ def cluster_sentences(sentences, num_clusters):
136
  # Return the ordered clustered sentences without similarity scores for display
137
  return [[sentence for _, sentence in cluster] for cluster in clustered_sentences]
138
 
 
139
  # Function to convert text to a downloadable file
140
  def get_text_file_download_link(text_to_download, filename='Output.txt', button_label="💾 Save"):
141
  buffer = BytesIO()
 
108
 
109
  return None
110
 
111
+
112
  def cluster_sentences(sentences, num_clusters):
113
  # Filter sentences with length over 10 characters
114
  sentences = [sentence for sentence in sentences if len(sentence) > 10]
115
 
116
+ # Check if the number of sentences is less than the desired number of clusters
117
+ if len(sentences) < num_clusters:
118
+ # If so, adjust the number of clusters to match the number of sentences
119
+ num_clusters = len(sentences)
120
+
121
  # Vectorize the sentences
122
  vectorizer = TfidfVectorizer()
123
  X = vectorizer.fit_transform(sentences)
 
142
  # Return the ordered clustered sentences without similarity scores for display
143
  return [[sentence for _, sentence in cluster] for cluster in clustered_sentences]
144
 
145
+
146
  # Function to convert text to a downloadable file
147
  def get_text_file_download_link(text_to_download, filename='Output.txt', button_label="💾 Save"):
148
  buffer = BytesIO()