def art_cloud_wl(acorpus): WC = WordCloud(background_color="white") WC.generate_from_lengths = MethodType(generate_from_lengths, WC) fig = plt.figure() if type(acorpus) is not type(str()): temp_str = "" for a in acorpus: temp_str += a + " " acorpus = temp_str # tokens = word_tokenize(acorpus) # if len(tokens): # wordcloud = WC.generate_from_lengths(tokens) # if type(acorpus) is type(""): wordcloud = WC.generate_from_lengths(acorpus) if not "wordcloud" in locals(): return None, None, None biggest_words = WC.biggest_words word_counts_fz = WC.word_counts_fz # wc = WordCloud().generate_from_frequencies(frequencies=di) plt.imshow(wordcloud, aspect="auto", interpolation="bilinear") plt.axis("off") plt.tight_layout(pad=0) st.pyplot(fig, use_column_width=True) return biggest_words, word_counts_fz, fig