jeremyjia / Games

Home Page Link:
https://jeremyjia.github.io/Games/
2 stars 7 forks source link

PDF中提取图片 n' 词云前后端综合demo #995

Open jeremyjia opened 7 months ago

jeremyjia commented 7 months ago

参考资料 http://www.360doc.com/content/12/0121/07/77611998_1083614856.shtml

waynexw commented 7 months ago

image 我求助chatGPT用Javascript先在我的主页上(waynexw.github.io/waynexw/)实现了基本功能,即选择PDF文件,然后把提取出来的图片显示在同一个页面上。 需解决的问题:

  1. 继续研究PyPDF2库,用python来实现同样的功能。
  2. 代码里只做了两个按钮,但是页面上显示了三个按钮,多出一个中文的“选择文件”,我问chatGPT为什么会这样,它说可能是开了页面翻译器,我觉得没开翻译器啊。对于这个问题,我现在还是没搞清楚。答:这个语句本身就会有一个按钮显示出来,如果想隐藏按钮,可以试试hidden属性。
waynexw commented 7 months ago

<!DOCTYPE html>

PDF Image Extractor

PDF Image Extractor v0.3

waynexw commented 3 months ago

image

ABOUT THE SOLUTION

app.py as below:

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)

index.html as below:

<!DOCTYPE html>

Word Cloud Generator

Word Cloud Generator





jeremyjia commented 2 months ago

词云这个小例子很好,综合了python Flask的前后端的调用。我把代码收录到了Games/python/i995目录下,并做了一些额外的研究,增加了新的endpoint可以对图像进行亮度调节处理,UI如下:

  1. 启动app.py
  2. 浏览器输入http://localhost:5000

image

jeremyjia commented 2 months ago

image

jeremyjia commented 2 months ago

继续扩展实现这个综合示程序,类似实现一个虚拟网络摄像机

jeremyjia commented 2 months ago

image