Sa-m commited on
Commit
756209b
·
verified ·
1 Parent(s): d6d183b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -7
app.py CHANGED
@@ -302,10 +302,9 @@ def DispersionPlot(textParty):
302
  print(f"Debug DispersionPlot: FreqDist sample: {list(fdistance.most_common(10))}") # Debug print
303
 
304
  # --- Improved word selection logic ---
305
- # Get common words, excluding very short words which might be punctuation/non-informative
306
- # or words that dispersion_plot might have trouble with.
307
  common_words_raw = fdistance.most_common(15) # Check a few more common words
308
- # Filter: length > 2, isalpha (to avoid punctuation), not just digits
309
  common_words_filtered = [(word, freq) for word, freq in common_words_raw if len(word) > 2 and word.isalpha() and not word.isdigit()]
310
  print(f"Debug DispersionPlot: Filtered common words: {common_words_filtered}") # Debug print
311
 
@@ -316,7 +315,6 @@ def DispersionPlot(textParty):
316
  word_Lst = [common_words_filtered[x][0] for x in range(5)]
317
 
318
  # Final check: Ensure words are present in the Text object (moby)
319
- # This is crucial for dispersion_plot
320
  final_word_list = [word for word in word_Lst if word in moby] # Check membership in the Text object
321
  print(f"Debug DispersionPlot: Final word list for plot: {final_word_list}") # Debug print
322
 
@@ -360,11 +358,8 @@ def DispersionPlot(textParty):
360
  buf.close() # Ensure buffer is closed on error
361
  traceback.print_exc()
362
  plt.close('all') # Aggressive close on error
363
- # Optionally return a placeholder image or None
364
  return None # Return None on error
365
 
366
-
367
-
368
  def word_cloud_generator(parsed_text_name, text_Party):
369
  """Generates the word cloud image."""
370
  buf = None # Initialize buffer
 
302
  print(f"Debug DispersionPlot: FreqDist sample: {list(fdistance.most_common(10))}") # Debug print
303
 
304
  # --- Improved word selection logic ---
305
+ # Get common words, handle potential IndexError if less than 5 unique words
 
306
  common_words_raw = fdistance.most_common(15) # Check a few more common words
307
+ # Filter: length > 2, isalpha (to avoid punctuation/non-informative), not just digits
308
  common_words_filtered = [(word, freq) for word, freq in common_words_raw if len(word) > 2 and word.isalpha() and not word.isdigit()]
309
  print(f"Debug DispersionPlot: Filtered common words: {common_words_filtered}") # Debug print
310
 
 
315
  word_Lst = [common_words_filtered[x][0] for x in range(5)]
316
 
317
  # Final check: Ensure words are present in the Text object (moby)
 
318
  final_word_list = [word for word in word_Lst if word in moby] # Check membership in the Text object
319
  print(f"Debug DispersionPlot: Final word list for plot: {final_word_list}") # Debug print
320
 
 
358
  buf.close() # Ensure buffer is closed on error
359
  traceback.print_exc()
360
  plt.close('all') # Aggressive close on error
 
361
  return None # Return None on error
362
 
 
 
363
  def word_cloud_generator(parsed_text_name, text_Party):
364
  """Generates the word cloud image."""
365
  buf = None # Initialize buffer