Python Chatterbot在flask服务器上没有响应

Python Chatterbot在flask服务器上没有响应,python,machine-learning,flask,chatterbot,Python,Machine Learning,Flask,Chatterbot,我正在学习如何为聊天机器人编程,并在网上学习如何使用flask开发一个简单的聊天机器人。然而,尽管我根据自己的喜好(HTML等)设计了flask站点,但我似乎无法从bot获得响应。如果我发送“你好”消息,则不会返回任何内容。我将chatterbot包与python一起使用。我想训练我的机器人能够谈论其他话题作为最终目标,但只是从默认的聊天回答开始。哦,顺便说一下,我没有收到来自PowerShell的错误消息。下面是我的Python和HTML代码。提前感谢你的帮助 Python: from fla

我正在学习如何为聊天机器人编程,并在网上学习如何使用flask开发一个简单的聊天机器人。然而,尽管我根据自己的喜好(HTML等)设计了flask站点,但我似乎无法从bot获得响应。如果我发送“你好”消息,则不会返回任何内容。我将chatterbot包与python一起使用。我想训练我的机器人能够谈论其他话题作为最终目标,但只是从默认的聊天回答开始。哦,顺便说一下,我没有收到来自PowerShell的错误消息。下面是我的Python和HTML代码。提前感谢你的帮助

Python:

from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer


app = Flask(__name__)
bot = ChatBot('Bob')
trainer = ChatterBotCorpusTrainer(bot)
trainer.train("chatterbot.corpus.english")


@app.route("/")
def home():
    return render_template("index.html")

@app.route("/get")
def get_bot_response():
    userText = request.args.get('msg')
    return str(bot.get_response(userText))

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

HTML:


聊天机器人
身体{
字体系列:monospace;
颜色:#fff;
}
h1{
显示:内联块;
字号:3em;
保证金:0;
填充:14px;
}
h3{
颜色:黑色;
字体大小:20px;
利润上限:3倍;
文本对齐:居中;
}
#聊天室{
左边距:自动;
右边距:自动;
宽度:40%;
边缘顶部:60像素;
}
#用户输入{
左边距:自动;
右边距:自动;
宽度:40%;
利润上限:70像素;
}
#文本输入{
宽度:40%;
边界:无;
边框底部:5px实心#00cc99;
字体系列:monospace;
字号:17px;
}
.userText{
颜色:白色;
字体系列:monospace;
字号:17px;
文本对齐:右对齐;
线高:30px;
}
.userText span{
背景色:#4169e1;
填充:10px;
边界半径:2px;
}
.botText{
颜色:白色;
字体系列:monospace;
字号:17px;
文本对齐:左对齐;
线高:30px;
}
.botText span{
背景色:#a4c639;
填充:10px;
边界半径:2px;
}
#花絮{
位置:绝对位置;
底部:0;
右:0;
宽度:300px;
}
.盒装{
左边距:自动;
右边距:自动;
宽度:78%;
边缘顶部:60像素;
边框:1px实心#00cc99;
}
.盒子{
边框:2px实心#00cc99;
}
欢迎来到我的聊天机器人
你好我叫鲍勃。你的个人聊天机器人!

你好很高兴认识你!

函数getBotResponse(){ var rawText=$(“#textInput”).val(); var userHtml='

'+rawText+“

”; $(“#textInput”).val(“”); $(“#聊天室”).append(userHtml); 文件 .getElementById(“用户输入”) .scrollIntoView({块:“开始”,行为:“平滑”}); $.get(“/get”,{msg:rawText}).done(函数(数据){ var botHtml='

'+data+“

”; $(“#聊天室”).append(botHtml); 文件 .getElementById(“用户输入”) .scrollIntoView({块:“开始”,行为:“平滑”}); }); } $(“#文本输入”)。按键(功能(e){ 如果(e.which==13){ getBotResponse(); } });
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>ChatBot</title>
    <link rel="stylesheet" type= "text/css" href="{{ url_for('static', filename='styles/style.css') }}">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <style>
      body {
        font-family: monospace;
        color: #fff;
      }
      h1 {
        display: inline-block;
        font-size: 3em;
        margin: 0;
        padding: 14px;
      }
      h3 {
        color: black;
        font-size: 20px;
        margin-top: 3px;
        text-align: center;
      }
      #chatbox {
        margin-left: auto;
        margin-right: auto;
        width: 40%;
        margin-top: 60px;
      }
      #userInput {
        margin-left: auto;
        margin-right: auto;
        width: 40%;
        margin-top: 70px;
      }
      #textInput {
        width:40%;
        border: none;
        border-bottom: 5px solid #00cc99;
        font-family: monospace;
        font-size: 17px;
      }
      .userText {
        color: white;
        font-family: monospace;
        font-size: 17px;
        text-align: right;
        line-height: 30px;
      }
      .userText span {
        background-color: #4169e1;
        padding: 10px;
        border-radius: 2px;
      }
      .botText {
        color: white;
        font-family: monospace;
        font-size: 17px;
        text-align: left;
        line-height: 30px;
      }
      .botText span {
        background-color: #a4c639;
        padding: 10px;
        border-radius: 2px;
      }
      #tidbit {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 300px;
      }
      .boxed {
        margin-left: auto;
        margin-right: auto;
        width: 78%;
        margin-top: 60px;
        border: 1px solid #00cc99;
      }
      .box {
        border: 2px solid #00cc99;
      }
    </style>


  </head>
  <body>
     <center>
    <h1 class="h1">Welcome to my ChatBot</h1>
    <h2>Hello! My name is Bob. Your personal chatbot!</h2>
    <div class="box"></div>
    <div class="boxed">
      <div>
        <div id="chatbox">
          <img src="{{url_for('static', filename= 'robot.jpg')}}" alt="bob" width="60px" height= "60px"/>
          <p class="botText">
            <span>Hi! Nice to meet you!</span>
          </p>
        </div>
        <div class="userInput">
          <input id="textInput" type="text" name="msg" placeholder="Message" />
        </div>
      </div>


      <script>
      function getBotResponse() {
        var rawText = $("#textInput").val();
        var userHtml = '<p class="userText"><span>' + rawText + "</span></p>";
        $("#textInput").val("");
        $("#chatbox").append(userHtml);
        document
            .getElementById("userInput")
            .scrollIntoView({ block: "start", behavior: "smooth" });
        $.get("/get", { msg: rawText }).done(function (data) {
            var botHtml = '<p class="botText"><span>' + data + "</span></p>";
            $("#chatbox").append(botHtml);
            document
                .getElementById("userInput")
                .scrollIntoView({ block: "start", behavior: "smooth" });
        });
    }
    $("#textInput").keypress(function (e) {
        if (e.which == 13) {
            getBotResponse();
        }
    });
        </script>

    </div>
  </body>
</html>