vidyasharma17 commited on
Commit
e5d6ef6
·
verified ·
1 Parent(s): ac6f72c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -44
app.py CHANGED
@@ -1,56 +1,54 @@
 
 
1
  from sklearn.feature_extraction.text import CountVectorizer
2
- from sklearn.naive_bayes import MultinomialNB
3
  import gradio as gr
4
 
5
- # Example data
6
- train_queries = [
7
- "How do I activate my card?",
8
- "What is the age limit for opening an account?",
9
- "Do you support Apple Pay or Google Pay?",
10
- ]
11
- train_labels = [0, 1, 2]
12
 
 
 
 
 
13
  responses = {
14
- 0: "To activate your card, please go to the app's settings.",
15
- 1: "The age limit for opening an account is 18 years.",
16
- 2: "Yes, we support Apple Pay and Google Pay.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
 
19
- label_to_intent = {0: "activate_my_card", 1: "age_limit", 2: "apple_pay_or_google_pay"}
20
-
21
- # Prepare the Naive Bayes model
22
- vectorizer = CountVectorizer()
23
- X_train = vectorizer.fit_transform(train_queries)
24
-
25
- clf = MultinomialNB()
26
- clf.fit(X_train, train_labels)
27
-
28
- # Define the chatbot response function
29
- def naive_bayes_response(user_input):
30
  vectorized_input = vectorizer.transform([user_input])
31
  predicted_label = clf.predict(vectorized_input)[0]
32
- return responses.get(predicted_label, "Sorry, I couldn't understand your query.")
33
-
34
- # Define Gradio interface
35
- def chatbot_interface(user_input):
36
- return naive_bayes_response(user_input)
37
 
38
- # UI design with Gradio
39
- with gr.Blocks() as demo:
40
- gr.Markdown("# Naive Bayes Chatbot")
41
- gr.Markdown("This is a chatbot powered by Naive Bayes that handles basic queries.")
42
- with gr.Row():
43
- with gr.Column():
44
- user_input = gr.Textbox(
45
- label="Your Query",
46
- placeholder="Type your question here...",
47
- lines=1,
48
- )
49
- submit_btn = gr.Button("Submit")
50
- with gr.Column():
51
- response = gr.Textbox(label="Chatbot Response", interactive=False)
52
- submit_btn.click(chatbot_interface, inputs=user_input, outputs=response)
53
 
54
- # Run the app
55
  if __name__ == "__main__":
56
- demo.launch()
 
 
1
+ import json
2
+ import pickle
3
  from sklearn.feature_extraction.text import CountVectorizer
 
4
  import gradio as gr
5
 
6
+ # Load the Naive Bayes model and vectorizer
7
+ with open("naive_bayes_model.pkl", "rb") as model_file:
8
+ clf = pickle.load(model_file)
 
 
 
 
9
 
10
+ with open("vectorizer.pkl", "rb") as vectorizer_file:
11
+ vectorizer = pickle.load(vectorizer_file)
12
+
13
+ # Define the responses dictionary
14
  responses = {
15
+ "activate_my_card": "To activate your card, log in to the app and navigate to the 'Activate Card' section.",
16
+ "age_limit": "The minimum age to use this service is 18 years.",
17
+ "apple_pay_or_google_pay": "Yes, you can use both Apple Pay and Google Pay with your card.",
18
+ "atm_support": "Your card is supported by ATMs that display the Visa or Mastercard logo.",
19
+ "automatic_top_up": "You can enable automatic top-up in the app under the 'Top-Up Settings' section.",
20
+ "balance_not_updated_after_bank_transfer": "If your balance hasn’t updated after a bank transfer, please wait for 24 hours. If the issue persists, contact support.",
21
+ "beneficiary_not_allowed": "Ensure that the beneficiary details are correct. Some accounts may have restrictions; check with customer support for clarification.",
22
+ "cancel_transfer": "To cancel a transfer, go to the 'Transaction History' section in the app and select the transfer you wish to cancel.",
23
+ "card_about_to_expire": "If your card is about to expire, a replacement will be sent automatically. Contact support if you haven’t received it.",
24
+ "card_arrival": "New cards usually arrive within 7-10 business days after being issued.",
25
+ "card_not_working": "If your card isn't working, ensure it is activated and has sufficient balance. Contact support if the issue persists.",
26
+ "change_pin": "You can change your PIN using the app or at any ATM with your card.",
27
+ "contactless_not_working": "Ensure your card supports contactless payments and check if the terminal accepts it. If the issue persists, contact support.",
28
+ "country_support": "Your card is supported in all countries where Visa/Mastercard is accepted. Check the app for restrictions.",
29
+ "declined_card_payment": "Card payments can be declined due to insufficient balance, incorrect PIN, or restrictions on the merchant. Check your app for details.",
30
+ "lost_or_stolen_card": "If your card is lost or stolen, block it immediately in the app under the 'Card Management' section and request a replacement.",
31
+ "pending_card_payment": "Pending payments are usually resolved within 2-3 business days. Contact support if the status doesn't update.",
32
+ "refund_not_showing_up": "Refunds can take up to 7 business days to appear. Check with the merchant or contact support if it takes longer.",
33
+ "top_up_failed": "Top-up failures may occur due to incorrect details or insufficient balance in the source account. Check your app for details.",
34
+ "transfer_not_received_by_recipient": "If the recipient hasn't received the transfer, ensure the details are correct. Contact support for further assistance.",
35
  }
36
 
37
+ # Define chatbot response logic
38
+ def chatbot_response(user_input):
 
 
 
 
 
 
 
 
 
39
  vectorized_input = vectorizer.transform([user_input])
40
  predicted_label = clf.predict(vectorized_input)[0]
41
+ return responses.get(predicted_label, "Sorry, I couldn't understand your question.")
 
 
 
 
42
 
43
+ # Define the Gradio interface
44
+ interface = gr.Interface(
45
+ fn=chatbot_response,
46
+ inputs=gr.Textbox(lines=2, placeholder="Ask your fintech question here..."),
47
+ outputs="text",
48
+ title="FinTech Chatbot",
49
+ description="A chatbot to handle fintech-related queries using a Naive Bayes model."
50
+ )
 
 
 
 
 
 
 
51
 
 
52
  if __name__ == "__main__":
53
+ # Launch the Gradio app
54
+ interface.launch()