├── iris.png ├── README.md └── app.py /iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalebu/Desktop-chatbot-app/HEAD/iris.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Knowledge based chatbot](https://kalebujordan.dev/) 2 | 3 | This a cross-platform desktop app built with [tkinter] which simply acts like a dictionary chatbot, you can send it a message and it will return a response on what it thinks the message is by fetching it in a very large dictionary. 4 | 5 | ## Getting started 6 | 7 | To get started with this app, you might have to clone or download the repository first; 8 | 9 | ```bash 10 | git clone https://github.com/Kalebu/Desktop-chatbot-app 11 | cd Desktop-chatbot-app 12 | Desktop-chatbot-app-> 13 | ``` 14 | 15 | ## Dependencies 16 | 17 | For Window user, there is no extra dependencies to be installed however for those in Linux or Mac sometimes Python does not come with Tkinter installed so you might have to install it manually; 18 | 19 | ```bash 20 | sudo apt-get install python3-tk 21 | ``` 22 | 23 | ## launching 24 | 25 | Now once installed launch it by running as you would run a normal python script and the gui for chatbot will pop up; 26 | 27 | ```bash 28 | python app.py 29 | ``` 30 | 31 | ### launched interface 32 | 33 | Your interface for the chatbot app will probably look like shown below; 34 | 35 | ![chatbot application](iris.png) 36 | 37 | ## Issues 38 | 39 | Are you facing any issue while trying to run the code, raise one and I will be looking forward to fix it as soon as I can. 40 | 41 | ## Contributions 42 | 43 | have something to add that will improve this projects, whether a documentation or codebase just fork it. 44 | 45 | ## Credits 46 | 47 | ALl the credits to [Kalebu](https://github.com/Kalebu/) 48 | 49 | ### Where to find me ? 50 | 51 | - [Personal Blog](https://kalebujordan.dev/) 52 | - [Telegram](https://t.me/kalebujordan) 53 | - [LinkedIn](https://www.linkedin.com/in/kalebu-gwalugano/) 54 | - [Twitter](https://twitter.com/j_kalebu) 55 | - [Instagram](https://www.instagram.com/kalebu_jordan/) 56 | - [Facebook](https://web.facebook.com/kalebu.jordan) 57 | - isaackeinstein(at)gmail.com 58 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import json 2 | from difflib import get_close_matches 3 | from tkinter import Tk, Entry, Button, Text, Scrollbar 4 | 5 | 6 | class Chatbot: 7 | def __init__(self, window): 8 | window.title('Iris Assitant') 9 | window.geometry('405x400') 10 | window.resizable(0, 0) 11 | self.message_session = Text(window, bd=3, relief="flat", font=( 12 | "Times", 10), undo=True, wrap="word") 13 | self.message_session.config( 14 | width=45, height=15, bg="#596", fg="white", state='disabled') 15 | self.overscroll = Scrollbar(window, command=self.message_session.yview) 16 | self.overscroll.config(width=20) 17 | self.message_session["yscrollcommand"] = self.overscroll.set 18 | self.message_position = 1.5 19 | self.send_button = Button(window, text='send', fg='white', bg='blue', width=9, font=( 20 | 'Times', 12), relief='flat', command=self.reply_to_you) 21 | self.Message_Entry = Entry(window, width=40, font=('Times', 12)) 22 | self.Message_Entry.bind('', self.reply_to_you) 23 | self.message_session.place(x=20, y=20) 24 | self.overscroll.place(x=370, y=50) 25 | self.send_button.place(x=0, y=360) 26 | self.Message_Entry.place(x=135, y=365) 27 | self.Brain = json.load(open('knowledge.json')) 28 | 29 | def add_chat(self, message): 30 | self.message_position += 1.5 31 | print(self.message_position) 32 | self.Message_Entry.delete(0, 'end') 33 | self.message_session.config(state='normal') 34 | self.message_session.insert(self.message_position, message) 35 | self.message_session.see('end') 36 | self.message_session.config(state='disabled') 37 | 38 | def reply_to_you(self, event=None): 39 | message = self.Message_Entry.get().lower() 40 | message = 'you: ' + message+'\n' 41 | close_match = get_close_matches(message, self.Brain.keys()) 42 | if close_match: 43 | reply = 'Iris: ' + self.Brain[close_match[0]][0] + '\n' 44 | else: 45 | reply = 'Iris: ' + 'Cant it in my knowledge base\n' 46 | self.add_chat(message) 47 | self.add_chat(reply) 48 | 49 | 50 | root = Tk() 51 | Chatbot(root) 52 | root.mainloop() 53 | --------------------------------------------------------------------------------