SantanuBanerjee commited on
Commit
7153885
·
verified ·
1 Parent(s): d050103

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -353,32 +353,31 @@ def extract_problem_domains(df,
353
  # top_words = [feature_names[index] for index in top_word_indices]
354
  # cluster_representations[i] = top_words
355
 
 
356
  try:
357
  center = kmeans.cluster_centers_[i]
358
  console_messages.append(f"Processing cluster {i}")
359
  console_messages.append(f"Center shape: {center.shape}, type: {type(center)}")
360
 
361
-
362
- if isinstance(center, np.ndarray) and center.ndim == 1:
363
- # Ensure center.argsort() returns a numpy array
364
- sorted_indices = center.argsort()
365
- if isinstance(sorted_indices, np.ndarray):
366
- sorted_indices = sorted_indices.tolist()
367
 
368
- # Extract top word indices
369
- top_word_indices = sorted_indices[-top_words:][::-1]
 
370
 
371
- # Debug output
372
- console_messages.append(f"Sorted indices: {sorted_indices}")
373
- console_messages.append(f"Top word indices for cluster {i}: {top_word_indices}")
374
-
375
- top_words = [feature_names[index] for index in top_word_indices]
376
- console_messages.append(f"Top words: {top_words}")
377
- cluster_representations[i] = top_words
378
- else:
379
- console_messages.append(f"Error: Cluster center is not a 1D array for cluster {i}")
380
 
 
 
 
 
 
 
 
381
 
 
382
 
383
  except Exception as e:
384
  console_messages.append(f"Error processing cluster {i}: {str(e)}")
 
353
  # top_words = [feature_names[index] for index in top_word_indices]
354
  # cluster_representations[i] = top_words
355
 
356
+
357
  try:
358
  center = kmeans.cluster_centers_[i]
359
  console_messages.append(f"Processing cluster {i}")
360
  console_messages.append(f"Center shape: {center.shape}, type: {type(center)}")
361
 
362
+ if not isinstance(center, np.ndarray):
363
+ center = np.array(center)
 
 
 
 
364
 
365
+ sorted_indices = center.argsort()
366
+ if isinstance(sorted_indices, list):
367
+ sorted_indices = np.array(sorted_indices)
368
 
369
+ top_word_indices = sorted_indices[-top_words:][::-1]
370
+
 
 
 
 
 
 
 
371
 
372
+ # Debug output
373
+ console_messages.append(f"Sorted indices: {sorted_indices}")
374
+ console_messages.append(f"Top word indices for cluster {i}: {top_word_indices}")
375
+
376
+ top_words = [feature_names[index] for index in top_word_indices]
377
+ console_messages.append(f"Top words: {top_words}")
378
+ cluster_representations[i] = top_words
379
 
380
+
381
 
382
  except Exception as e:
383
  console_messages.append(f"Error processing cluster {i}: {str(e)}")