An online wordcloud generator

I made an online wordcloud generator to share with you.
This app can change the content, font style and the shape of outline at any time.

Here is the result of test:


My example code:

import matplotlib.pyplot as plt
import jieba
from wordcloud import wordcloud
import streamlit as st
import pandas as pd
import os
st.set_page_config(layout="centered")

lunkuo=[]
for root, dirs, files in os.walk(r"D:\streamlit公众号\词云\轮廓图"):
      for file in files:
             filename=os.path.join(root, file)
             lunkuo.append(filename)

ziti=[]
for root, dirs, files in os.walk(r"D:\streamlit公众号\词云\字体"):
      for file in files:
             filename=os.path.join(root, file)
             ziti.append(filename)

uploadedfile=st.file_uploader("请上传词云内容txt", type=["txt"])
if uploadedfile is not None:
    text = pd.read_table(uploadedfile, encoding='utf-8')
    cut_text = jieba.cut(str(text).replace("columns","").replace("row",""))
    wc = wordcloud.WordCloud(
        font_path=st.selectbox("请选择一种字体",(ziti)),
        background_color='white',  # 背景颜色
        width=1000,
        height=1000,
        max_font_size=80,  # 字体大小
        min_font_size=1,
        mask=plt.imread(st.selectbox("请选择一种轮廓图",(lunkuo))),  # 背景图片
        max_words=10000
    )
    wc.generate(" ".join(cut_text))
    wc.to_file('ciyun.png')
    col1, col2, col3=st.columns([0.2,1,0.2])
    with col1:
        st.empty()
    with col2:
        st.image('ciyun.png', use_column_width='auto', caption='生成的词云图',output_format="png")
    with col3:
        st.empty()

else:
    st.warning("你需要上传词云内容文本文件")

Welcome my friends to join the wechat group to exchange the streamlit use experiences.

1 Like

Mazing!