我正在使用深度学习模型和烧瓶来构建聊天机器人,但该机器人未给出响应,并且显示了此错误
GET /run?msg=salut HTTP/1.1" 404 -
这是html代码
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<h1>SAM Chatbot</h1>
<div>
<div id="chatbox">
<p class="botText"><span>Salut je suis le Bot.</span></p>
</div>
<div id="userInput">
<input id="textInput" type="text" name="msg" placeholder="Message">
<input id="buttonInput" type="submit" value="Send">
</div>
<script>
function chatbot_response() {
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("run", { 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) {
chatbot_response();
}
});
$("#buttonInput").click(function() {
chatbot_response();
})
</script>
</div>
</body>
</html>
from flask import Flask, render_template, request, jsonify
import tensorflow as tf
import numpy as np
import keras
from keras.models import load_model
import keras.preprocessing.text
import os
import h5py
from utils import loadChatbot
import pickle
from chatgui import chatbot_response, getResponse
#from utils import translate
#! /usr/bin/python
# -*- coding:utf-8 -*-
app = Flask(__name__, static_url_path='/static')
chatbot_model = loadChatbot('chatbot_model.h5')
"""global graph
graph = tf.get_default_graph()"""
@app.route('/')
def accueil():
return render_template('index.html')
@app.route('/',methods=['GET', 'POST'])
def chatbot_response():
print ("run")
userText = request.args.get('msg')
if userText != '':
res = chatbot_model.predict(userText)
return res
@app.errorhandler(500)
def server_error(error):
return render_template('error.html'), 500
if __name__ == '__main__':
app.run(debug=True)
答案 0 :(得分:0)
您似乎没有为Flask设置端口(必须绑定到Heroku提供的端口)
app.run(debug=True, port=int(os.environ.get("PORT", 5000)), host='0.0.0.0')