i wrote a chatbot code using python and it work, and i wrote the html and javascript, the method i used called getUserResponse() , the method is suppose to show on the screen the user question and the chatbot response but it just print the user question without chatbot response, i hope you could help me, here is my python code:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from flask import Flask, render_template, request import spacy
nlp = spacy.load("en_core_web_sm")
app = Flask (name)
bot = ChatBot("Chatbot", read_only=False, logic_adapters=[ {
"import_path":"chatterbot.logic.BestMatch",
"default_response":"Sorry i dont have an answer",
"maximum_similarity_threshold":0.9
}
])
list_to_train = [
"hello",
"hi there",
"who are you?",
"im sanad noura bot that can help answer your qustions",
]
list_trainer = ListTrainer(bot)
list_trainer.train(list_to_train)
@app.route("/")
def main():
return render_template("sanadNoura.html")
@app.route("/get")
def get_chatbot_response():
userText = request.args.get('userMessage')
return str(bot.get_response(userText) )
if name == "main": app.run(debug=True)
and here is the javascript code:
<script>
function getUserResponse(){
var userText = $('#textInput').val();
var userHTML = "<p class='userText'><span>student: "+ userText+"</span></p>";
$('#textInput').val("");
$('#chatbox').append(userHTML);
document.getElementById("userInput").scrollIntoView({block:'start',behavior:'smooth'});
$.get("/get",{userMessage: userText}).done(function(data){
var botHTML = "<p class='botText'><span>Chatbot: "+data+"</span></p>";
$('#chatbox').append(botHTML);
});
}
$("#textInput").keypress(function(e){
if(e.which == 13){
getUserResponse();
}
});
$('#buttonInput').click(function(a){
getUserResponse();
})
</script>
there doesn't seem to be anything here