Untitled
unknown
plain_text
2 years ago
2.5 kB
6
Indexable
from flask import Flask, render_template, request, jsonify from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer app = Flask(__name__) # Create a chatbot instance bot = ChatBot('RemodelingBot') # Create a new trainer for the chatbot trainer = ChatterBotCorpusTrainer(bot) # Train the chatbot on English language data trainer.train('chatterbot.corpus.english') # Custom training data for home remodeling trainer.train([ "How much does a kitchen remodel cost?", "The cost of a kitchen remodel varies based on factors like size and materials used.", "Are you the current homeowner?", "What room/rooms are you considering remodeling?", "When do you anticipate wanting to break ground on this project after you've made a hiring decision?", "Are you available at the moment to have a short phone call with one of our design experts?", "Were you aware we have a $1000 off promotion going until the end of the month?", "Great, we do have the promotion I mentioned above and to qualify you just would need to sign up with us prior to the start of next month, when is a good day/time to have one of our design experts reach out?" ]) @app.route('/') def index(): return render_template('index.html') @app.route('/get_response', methods=['POST']) def get_response(): user_message = request.form['user_message'] response = str(bot.get_response(user_message)) # Additional logic to handle specific questions if "current homeowner" in user_message.lower(): response += "\nPlease let us know if you are the current homeowner." elif "considering remodeling" in user_message.lower(): response += "\nWhich room/rooms are you considering remodeling?" elif "break ground" in user_message.lower(): response += "\nWhen do you anticipate wanting to break ground on this project after you've made a hiring decision?" elif "short phone call" in user_message.lower(): response += "\nAre you available at the moment to have a short phone call with one of our design experts?" elif "aware of promotion" in user_message.lower(): response += "\nGreat, we do have the promotion I mentioned above and to qualify you just would need to sign up with us prior to the start of next month, when is a good day/time to have one of our design experts reach out?" return jsonify({'response': response}) if __name__ == '__main__': app.run(debug=True)
Editor is loading...
Leave a Comment