Code
Code
Import tkinter as tk
Import random
Import pyttsx3
Patterns = [
(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(‘{}’,
random.randint(1000, 5000)), ‘The balance for account number {} is Rs.{}.’.format(‘{}’,
random.randint(1000, 5000)), ‘Account number {} has a balance of Rs.{}.’.format(‘{}’,
random.randint(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?”])
Class ChatbotGUI:
Self.master = master
Master.title(“Banking Chatbot”)
Master.geometry(“400x450”)
Master.config(bg=”#f0f0f0”)
Self.engine = pyttsx3.init()
Def send_message(self):
User_input = self.user_input.get()
Self.user_input.delete(0, tk.END)
Self.display_message(“You: “ + user_input)
Response = chatbot.respond(user_input)
Self.display_message(“Bot: “ + response.format(user_input.split()[-1]))
Self.engine.say(response)
Self.engine.runAndWait()
Self.chat_history.configure(state=’normal’)
Self.chat_history.configure(state=’disabled’)
Self.chat_history.yview(tk.END)
Def clear_history(self):
Self.chat_history.configure(state=’normal’)
Self.chat_history.delete(1.0, tk.END)
Self.chat_history.configure(state=’disabled’)
Def exit_chatbot(self):
Self.master.destroy()
Def main():
Root = tk.Tk()
App = ChatbotGUI(root)
Root.mainloop()
If __name__ == “__main__”:
Main()