-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecomBot.py
80 lines (66 loc) · 2.38 KB
/
ecomBot.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
76
77
78
79
80
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer
from flask import Flask, render_template, request
from chatterbot.response_selection import get_random_response
import logging
logger = logging.getLogger()
logger.setLevel(logging.CRITICAL)
def remove_hyphens(statement):
"""
Remove hypnens.
"""
statement.text = statement.text.replace('-', '')
return statement
app = Flask(__name__)
bot = ChatBot(name='Anakin', read_only=True,
response_selection_method=get_random_response,
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database_uri='sqlite:///database.sqlite3',
logic_adapters=[
{
'import_path': 'chatterbot.logic.SpecificResponseAdapter',
'input_text': 'empty',
'output_text': ''
},
{
'import_path': 'chatterbot.logic.BestMatch',
'default_response': 'i honestly have no idea how to respond to that',
'maximum_similarity_threshold': 0.9
},
{
'import_path': 'chatterbot.logic.MathematicalEvaluation'
}
]
)
bot.preprocessors.append(
remove_hyphens
)
trainer = ChatterBotCorpusTrainer(bot)
trainer.train(
"data/greetings.yml",
"data/ecom.yml"
)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/get")
def get_bot_response():
req = request.args.get("msg")
if req.lower() == 'bye' or req.lower() == 'thanks' or req.lower() == 'get lost':
return ("Hope I was able to help you.Thank you.Have a good day")
elif (req.lower().find("search") != -1):
#item=req[6:]+"on flipkart"
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
query = req[6:]+" on flipkart"
# print("Bot: Select any link and find your desired product on flipkart ,amazon and other trusted sites. Happy shopping!")
for j in search(query, tld="co.in", num=5, stop=5, pause=2):
return j
else:
response = bot.get_response(req)
return str(response)
if __name__ == "__main__":
app.run(debug=True)