使用python + Vue搭建词云网站
界面预览

使用界面

效果图

python代码
import numpy as npy
import jieba
from flask_cors import *
from wordcloud import WordCloud
from PIL import Image
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
return render_template("index.html")
@app.route("/api/ci", methods=["POST"])
@cross_origin()
def ci():
ci_data = request.get_json()
text = ci_data["text"]
filename = ci_data["filename"]
text = " ".join(jieba.lcut(text))
mask = npy.array(Image.open("static/img/" + filename))
ci_cloud = WordCloud(background_color="white", font_path="msyh.ttc", mask=mask).generate(text)
path = "static/ciimg/mxt-" + filename
ci_cloud.to_file(path)
return jsonify({"img": "../" + path})
@app.route("/api/upload", methods=["POST"])
@cross_origin()
def upload():
img = request.files.get("file")
img_name = img.filename
path = "static/img/" + img_name
img.save(path)
return jsonify({"code": "1"})
if __name__ == "__main__":
app.run()