-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
75 lines (62 loc) · 2.51 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/python3
from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.response_selection import get_random_response
import random
#from chatterbot.trainers import ChatterBotCorpusTrainer
from botConfig import myBotName, chatBG, botAvatar, useGoogle, confidenceLevel
##Experimental Date Time
from dateTime import getTime, getDate
import logging
logging.basicConfig(level=logging.INFO)
application = Flask(__name__)
chatbotName = myBotName
print("Bot Name set to: " + chatbotName)
print("Confidence level set to " + str(confidenceLevel))
bot = ChatBot(
"ChatBot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': confidenceLevel,
'default_response': 'IDKresponse'
}
],
response_selection_method=get_random_response, #Comment this out if you want best response
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="botData.sqlite3"
)
bot.read_only=True #Comment this out if you want the bot to learn based on experience
print("Bot Learn Read Only:" + str(bot.read_only))
#You can comment these out for production later since you won't be training everytime:
#bot.set_trainer(ChatterBotCorpusTrainer)
#bot.train("data/trainingdata.yml")
def tryGoogle(myQuery):
#print("<br>Try this from my friend Google: <a target='_blank' href='" + j + "'>" + query + "</a>")
return "<br><br>You can try this from my friend Google: <a target='_blank' href='https://www.google.com/search?q=" + myQuery + "'>" + myQuery + "</a>"
@application.route("/")
def home():
return render_template("index.html", botName = chatbotName, chatBG = chatBG, botAvatar = botAvatar)
@application.route("/get")
def get_bot_response():
userText = request.args.get('msg')
botReply = str(bot.get_response(userText))
if botReply is "IDKresponse":
botReply = str(bot.get_response('IDKnull')) ##Send the i don't know code back to the DB
if useGoogle == "yes":
botReply = botReply + tryGoogle(userText)
elif botReply == "getTIME":
botReply = getTime()
print(getTime())
elif botReply == "getDATE":
botReply = getDate()
print(getDate())
return botReply
if __name__ == "__main__":
application.run()
#application.run(host='0.0.0.0', port=80)