Open jeremyjia opened 7 months ago
我求助chatGPT用Javascript先在我的主页上(waynexw.github.io/waynexw/)实现了基本功能,即选择PDF文件,然后把提取出来的图片显示在同一个页面上。 需解决的问题:
<!DOCTYPE html>
from flask import Flask, render_template, request from wordcloud import WordCloud import matplotlib.pyplot as plt from io import BytesIO import base64
app = Flask(name)
@app.route('/') def index(): return render_template('index.html')
@app.route('/generate', methods=['POST']) def generate_wordcloud(): words = request.form['words'] weights = request.form['weights'] wordcloud = WordCloud(width=800, height=400).generate_from_frequencies(dict(zip(words.split(','), map(int, weights.split(','))))) plt.figure(figsize=(8, 4)) plt.imshow(wordcloud, interpolation='bilinear') plt.axis('off') plt.tight_layout(pad=0) buffer = BytesIO() plt.savefig(buffer, format='png') buffer.seek(0) img_str = base64.b64encode(buffer.read()).decode('utf-8') plt.close() return f''
if name == 'main': app.run(debug=True)
<!DOCTYPE html>
参考资料 http://www.360doc.com/content/12/0121/07/77611998_1083614856.shtml