Code
Import tkinter as tk
From tkinter import scrolledtext, messagebox
From [Link] import Chat, reflections
Import random
Import pyttsx3
# Define patterns and responses for the chatbot
Patterns = [
(r’hi|hello|hey’, [‘Hello!’, ‘Hi there!’, ‘How can I help you today?’]),
(r’(.*) balance’, [‘Before I can check your balance, could you please provide your account number?’]),
(r’my account number is (\d+)’, [‘Your account balance for account number {} is Rs.{}.’.format(‘{}’,
[Link](1000, 5000)), ‘The balance for account number {} is Rs.{}.’.format(‘{}’,
[Link](1000, 5000)), ‘Account number {} has a balance of Rs.{}.’.format(‘{}’,
[Link](1000, 5000))]),
(r’transfer (.*) to (.*)’, [‘Transferring Rs.\\1 to account Rs.\\2.’, ‘Transfer of Rs.\\1 to account Rs.\\2
successful.’]),
(r’(?:what|which) types of loans (?:do you offer|are available)’, [‘We offer various types of loans
including personal loans, home loans, and car loans. What type of loan are you interested in?’]),
(r’(?:I want to borrow|\bborrow\b) (.+?)(?: home)? Loan’, [‘Great! Based on your request, you could
be eligible for a {} amount of {}. How would you like to proceed?’, ‘We can offer you a {} loan based on
your financial profile. How would you like to proceed?’]),
(r’(?:explain|define|tell me about) (?:the )?loan terms’, [‘We offer loan terms ranging from {} years to
{} months. What term length are you considering?’, ‘The loan term can be customized based on your
preference. Would you like a longer or shorter term?’]),
(r’(?:.*) (?:application process)’, [‘To apply for a loan, you can visit our website and fill out an online
application form. You will need to provide information about your income, employment, and credit
history.’]),
(r’(?:.*) (?:eligibility criteria)’, [‘Our eligibility criteria include factors such as credit score, income level,
and employment status. Would you like more detailed information about our eligibility requirements?’]),
(r’(?:.*) (?:open|create) (?:a)? (?:new)? (?:bank )?account’, [‘You can easily open a new account online
or visit our nearest branch.’]),
(r’(.*) (transaction history|transactions)’, [‘You can view your transaction history by logging into your
online banking account.’]),
(r’(.*) (help|assistance)’, [“Sure! How can I assist you today?”, “I’m here to help. What do you need
assistance with?”]),
(r’(.*)’, [“I’m sorry, I don’t understand. Could you please rephrase your question?”])
# Create a chatbot instance
Chatbot = Chat(patterns, reflections)
Class ChatbotGUI:
Def __init__(self, master):
[Link] = master
[Link](“Banking Chatbot”)
[Link](“400x450”)
[Link](bg=”#f0f0f0”)
Self.chat_history = [Link](master, width=40, height=15, bg=”#ffffff”, font=(“Arial”,
10))
Self.chat_history.grid(row=0, column=0, padx=10, pady=10, columnspan=2)
Self.input_label = [Link](master, text=”You:”, bg=”#f0f0f0”, font=(“Arial”, 10))
Self.input_label.grid(row=1, column=0, padx=10, pady=5, sticky=”e”)
Self.user_input = [Link](master, width=30, font=(“Arial”, 10))
Self.user_input.grid(row=1, column=1, padx=10, pady=5, sticky=”w”)
Self.send_button = [Link](master, text=”Send”, command=self.send_message, bg=”#0080ff”,
fg=”#ffffff”, font=(“Arial”, 10, “bold”))
Self.send_button.grid(row=2, column=0, columnspan=2, padx=10, pady=10)
Self.clear_button = [Link](master, text=”Clear History”, command=self.clear_history,
bg=”#ff0000”, fg=”#ffffff”, font=(“Arial”, 10, “bold”))
Self.clear_button.grid(row=3, column=0, padx=10, pady=10, sticky=”ew”)
Self.exit_button = [Link](master, text=”Exit”, command=self.exit_chatbot, bg=”#808080”,
fg=”#ffffff”, font=(“Arial”, 10, “bold”))
Self.exit_button.grid(row=3, column=1, padx=10, pady=10, sticky=”ew”)
# Initialize text-to-speech engine
[Link] = [Link]()
Def send_message(self):
User_input = self.user_input.get()
Self.user_input.delete(0, [Link])
Self.display_message(“You: “ + user_input)
Response = [Link](user_input)
Self.display_message(“Bot: “ + [Link](user_input.split()[-1]))
# Text-to-speech conversion for bot’s response
[Link](response)
[Link]()
Def display_message(self, message):
Self.chat_history.configure(state=’normal’)
Self.chat_history.insert([Link], message + “\n”)
Self.chat_history.configure(state=’disabled’)
Self.chat_history.yview([Link])
Def clear_history(self):
Self.chat_history.configure(state=’normal’)
Self.chat_history.delete(1.0, [Link])
Self.chat_history.configure(state=’disabled’)
Def exit_chatbot(self):
If [Link](“Exit”, “Are you sure you want to exit?”):
[Link]()
Def main():
Root = [Link]()
App = ChatbotGUI(root)
[Link]()
If __name__ == “__main__”:
Main()