-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
90 lines (79 loc) · 2.71 KB
/
main.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
81
82
83
84
85
86
87
88
89
90
"""
Made by - Aditya mangal
Purpose - Python mini project
Date - 18 october 2020
"""
import re
from nltk.util import pr
from termcolor import cprint, colored
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import text2emotion as te
import time
chatbot = ChatBot("Bot")
trainer = ChatterBotCorpusTrainer(chatbot)
available = "\nAvailable languages >> \nbengali, chinese, english, french, german, hebrew, hindi, indonesian, italian,japanese, korean, marathi,\n oriya, persian, portuguese, russian, spanish, swedish, telugu, thai, traditionalchinese, turkish"
print(colored(available, "yellow"))
while True:
language = input(
"\n\nIn which language do you want to start the conversation ? >> "
).lower()
if language in available:
break
else:
print(
f"Sorry {language} language is not available,\n please select from the above list."
)
trainer.train(f"chatterbot.corpus.{language}")
def get_emoji(query):
emotion = te.get_emotion(query)
# taking list of emotion values in v
v = list(emotion.values())
# taking list of emotion keys in v
k = list(emotion.keys())
emotion = k[v.index(max(v))] # Getting user's emotion
emotion_dict = {
"Happy": "😊",
"Angry": "😠",
"Surprise": "😯",
"Sad": "😟",
"Fear": "😨",
}
emoji = emotion_dict.get(f"{emotion}") # Getting emoji of the emotion
return emoji
if __name__ == "__main__":
cprint("#" * 80, "magenta")
cprint(
(f" \ ___| | | | | ").center(50),
"yellow",
)
cprint(
(f" _ \ | __ \ _` | __| __ \ _ \ __| ").center(50),
"yellow",
)
cprint(
(f" ___ \ _____| | | | | ( | | | | ( | | ").center(50),
"yellow",
)
cprint(
(f" _/ _\ \____|_| |_| \__._| \__| _.__/ \___/ \__| ").center(50),
"yellow",
)
cprint("#" * 80, "magenta")
print("You can exit by typing exit or bye\n")
name = input("Enter your name:")
cprint((f"Start Chatting").center(20), "yellow")
print()
while True:
query = input(colored(f" {name}>> ", "red"))
if "exit" in query.lower() or "bye" in query.lower():
print(colored("Bot>> Bye :) See you soon.....", "green"))
exit()
else:
if language.lower() == "english":
emoji = get_emoji(query)
print(
colored(f"Bot>> {chatbot.get_response(query)} [{emoji} ]", "green")
)
else:
print(colored(f"Bot>> {chatbot.get_response(query)}", "green"))