SDUWH2019-2020寒假python实训--my_main

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)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KingoKing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值