from flask import Flask, render_template, request, jsonify
import os, numpy as np
my_app = Flask(__name__)
icon_tag_list = {'robot':{'img':'/static/img/dhf.jpg','imgcss':'imgleft','spancss':'spanleft'},
'user':{'img':'/static/img/z.jpg','imgcss':'imgright','spancss':'spanright'}}
# 用户信息存储
user_chat_content = {
'username':'主人',
'icontag':[('robot','您好主人,请问有什么可以为您效劳的?'),]
}
@my_app.route('/')
def my_welcome():
return render_template('chat2.html',chat_content=user_chat_content,icon_tag=icon_tag_list)
# 对话窗口界面
@my_app.route('/chatres', methods=['POST', 'GET'])
def my_chat():
con = request.form['con'] # 获取post过来的参数,如果是get使用request.args.get()
user_chat_content['icontag'].append(('user',con))
# 如下添加对应回答内容
# user_chat_content['icontag'].append(('robot', my_chat_response.chat_response(con)))
return render_template('chat2.html',chat_content=user_chat_content,icon_tag=icon_tag_list)
#下载图片下载并排展示的界面
@my_app.route('/download/<content>')
def my_show_img(content):
#查看download/content下的图片极其所有文件
img_list = [f'{content}/{i}' for i in os.listdir(f'static/download/{content}') if os.path.splitext(i)[1] == '.jpg']
return render_template('imgshow.html', img_list=img_list)
# 做照片墙的处理
@my_app.route('/repage/<img_name>', methods=['GET'])
def my_repage_show(img_name):
# 接收到的参数的处理
imgpath_ori = request.args.get('imgpath')
if r'\u' in imgpath_ori:
imgpath = request.args.get('imgpath').encode('unicode_escape').decode()
elif r'\x' in imgpath_ori:
imgpath = request.args.get('imgpath').encode('raw_unicode_escape').decode()
else:
imgpath = imgpath_ori
#如下进行照片墙的处理,图片地址列表,列表大小为100*100,一维
# imgpath格式为: ‘李小龙/李小龙_1.jpg’
# p_path_list = my_img_process.p_pic_wall_main(imgpath)
return render_template('facepage.html', path_list=p_path_list)
@my_app.route('/test', methods=['GET'])
def my_repage_show_test():
#测试使用,用于调整
p_path_list = ['/static/download/李小龙_rect/rect_李小龙_1.jpg' for i in range(102)]
return render_template('facepage.html', path_list=p_path_list)
@my_app.route('/api/mnist', methods=['POST'])
def mnist():
input = ((255 - np.array(request.json, dtype=np.uint8)) / 255.0).reshape(1, 784)
#返回两个列表,分别代表对应的识别概率,regression convolution
# output1 = [0.003,0.01,0.007,0.89,0.012,0.008,0.014,0.007,0.026,0.023]
# output2 = [0.002,0.007,0.002,0.932,0.002,0.008,0.012,0.006,0.016,0.013]
return jsonify(results=[output1, output2])
@my_app.route('/mnist', methods=['GET'])
def mnist_main():
return render_template('digital.html')
if __name__ == "__main__":
my_app.run(debug=True)
SDUWH2019-2020寒假python实训--my_main
最新推荐文章于 2024-05-14 11:00:23 发布