import tkinter as tk
from tkinter import scrolledtext
from nltk.chat.util import Chat, reflections
import time
tech_support_responses = [
(r"Hello", ["Hi, How can i support you?"]),
(r"my PC not turning ON", ["Have you checked if it's plugged in?"]),
(r"Yes", ["restart and connet to internet"]),
(r"No", ["Please explain in detail"]),
(r"I can't connect to the internet", ["Have you tried restarting your router?"]),
(r"my PC is running slow", ["Try clearing your browser cache"]),
(r"OK", ["It worked?"]),
(r"how do I reset my password\?", ["You can reset your password by visiting our website and following the instructions"])
,
(r".*", ["Sorry, I cannot answer this."]),
(r" Thanks", ["Bye! hope your issue is solved" ])
]
counselling_responses = [
(r"Hello", ["Hi, How are you feeling today?"]),
(r"I feel (.*)", ["Why do you feel {0}?", "I'm sorry to hear that. Can you tell me more about why you feel {0}?"]),
(r"(.*) (depressed|sad|unhappy|lonely|dying)", ["I'm here to listen. What's been bothering you?", "It's okay to feel down sometimes. What's been on your mind?"]),
(r"I need someone to talk to", ["I'm here to listen. You can share anything with me"]),
(r".*", ["Sorry, I cannot help you in this"]),
(r"Thanks and Bye",
["Bye! hope your issue is solved" ]) ,
]
tech_support_chatbot = Chat(tech_support_responses, reflections)
counselling_chatbot = Chat(counselling_responses, reflections)
def send_message():
message = user_input.get()
user_input.delete(0, tk.END)
chat_history.config(state=tk.NORMAL)
chat_history.insert(tk.END, "You: " + message + "\n", "user")
chat_history.config(state=tk.DISABLED)
chat_history.see(tk.END)
chat_history.config(state=tk.NORMAL)
chat_history.insert(tk.END, "Bot is typing...", "bot_typing")
chat_history.see(tk.END)
chat_history.config(state=tk.DISABLED)
root.update_idletasks()
time.sleep(1)
if chat_mode.get() == "Tech Support":
response = tech_support_chatbot.respond(message)
else:
response = counselling_chatbot.respond(message)
chat_history.config(state=tk.NORMAL)
chat_history.delete("bot_typing.first", "bot_typing.last")
chat_history.insert(tk.END, "Bot: " + response + "\n", "bot")
chat_history.config(state=tk.DISABLED)
chat_history.see(tk.END)
root = tk.Tk()
root.title("Chatbot Counselling & Tech Support")
chat_history = scrolledtext.ScrolledText(root, wrap=tk.WORD)
user_input = tk.Entry(root)
send_button = tk.Button(root, text="Send", command=send_message)
chat_mode = tk.StringVar(value="Tech Support")
mode_selector = tk.Radiobutton(root, text="Tech Support", variable=chat_mode, value="Tech Support")
mode_selector2 = tk.Radiobutton(root, text="Counselling", variable=chat_mode, value="Counselling")
chat_history.config(state=tk.DISABLED)
chat_history.tag_config("user", foreground="blue")
chat_history.tag_config("bot", foreground="red")
chat_history.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
user_input.grid(row=1, column=0, padx=5, pady=5, sticky="ew")
send_button.grid(row=1, column=1, padx=5, pady=5, sticky="e")
mode_selector.grid(row=2, column=0, padx=5, pady=5, sticky="w")
mode_selector2.grid(row=2, column=1, padx=5, pady=5, sticky="w")
root.mainloop()