用户使用烧瓶输入文本时如何获得响应消息?

时间:2019-10-25 12:03:48

标签: python html flask chatbot

我使用for循环创建了一个聊天机器人。在浏览器中,当用户输入文本时它没有给出响应。

我尝试如下:

app.py:

import flask
from flask import Flask, render_template, request
from werkzeug.wrappers import Request, Response
import pandas as pd
import re
#####***** Reading the data
data=pd.read_excel("path",sheet_name='Sheet2')
#######**** Converting columns to a lists
userList=data["User"].tolist()
cbList=data["CB"].tolist()
app = Flask(__name__)
##########***** asking user to enter their questions and giving responses 
bot_response=[]
for i in range(0,len(userList)):
        user=input("User:")
        if user=='':
            print("Bye")
            break
        userReg=re.sub('[^A-Za-z0-9]'," ",user.lower())
        userRegSplit=(userReg.split())
        ud=str(userList[i]).lower()
        ud=re.sub('[^A-Za-z0-9]'," ",ud)
        newList=ud.split()
        commonWords=[x for x in newList if x in userRegSplit]
        if len(commonWords)==len(newList):
            bot_response.append(cbList[i])
            print(bot_response)
@app.route('/')
def CBApp():
    return render_template('CBApp.html')
@app.route("/get")
def get_bot_response():
    userText = request.args.get('msg')
    return str(bot_response.get_response(userText))
if __name__=='__main__':
    from werkzeug.serving import run_simple
    app.debug=True
    run_simple('localhost',port,app)

html模板如下所示:

 [1]: https://i.stack.imgur.com/rY4tW.png

建议我哪里出问题了?

0 个答案:

没有答案