聊天机器人chatbot

· · 个人记录


from flask import Flask,render_template,request,redirect
from flask_bootstrap import Bootstrap
import aiml
k = aiml.Kernel()
k.learn("cn-startup.xml")
k.respond("load aiml cn")
k.respond("start")

app = Flask(__name__)
bootstrap = Bootstrap(app)

@app.route('/',methods=['GET','POST'])
def chat():
    if request.method == 'POST':
        inpt = request.form.get('user_input')
        response = k.respond(inpt)
    else:
        response = None
    return render_template('chat.html',response=response)

@app.route('/introduce')
def intro():
    return render_template('intro.html')

@app.route('/login',methods=['GET','POST'])
def login():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        if username == 'admin' and password == '123456':
            return redirect('/')
        else:
            return 'Invalid username or password.'
    return render_template('login.html')


if __name__=='__main__':
    app.run()