Spaces:
Sleeping
Sleeping
| import pickle | |
| from sklearn.feature_extraction.text import CountVectorizer | |
| import gradio as gr | |
| # Load Naive Bayes model and vectorizer | |
| with open("naive_bayes_model.pkl", "rb") as model_file: | |
| clf = pickle.load(model_file) | |
| with open("vectorizer.pkl", "rb") as vectorizer_file: | |
| vectorizer = pickle.load(vectorizer_file) | |
| # Define responses dictionary | |
| responses = { | |
| "activate_my_card": "To activate your card, log in to the app and navigate to the 'Activate Card' section.", | |
| "age_limit": "The minimum age to use this service is 18 years.", | |
| "apple_pay_or_google_pay": "Yes, you can use both Apple Pay and Google Pay with your card.", | |
| # Add remaining responses here... | |
| } | |
| # Define chatbot response logic | |
| def chatbot_response(user_input): | |
| vectorized_input = vectorizer.transform([user_input]) | |
| predicted_label = clf.predict(vectorized_input)[0] | |
| return responses.get(predicted_label, "Sorry, I couldn't understand your question.") | |
| # Define UI description with sample questions | |
| description = """ | |
| ### FinTech Chatbot | |
| This chatbot can assist you with a variety of fintech-related queries. Below are some sample questions you can ask: | |
| - How do I activate my card? | |
| - What is the minimum age required to use this service? | |
| - Can I use Apple Pay with my card? | |
| - Which ATMs can I use my card with? | |
| - How can I set up automatic top-up for my account? | |
| - Why hasn't my balance updated after making a bank transfer? | |
| - Why can’t I add a beneficiary to my account? | |
| - Can I cancel a transfer I’ve made? | |
| - What should I do if my card is about to expire? | |
| - How long does it take for a new card to arrive? | |
| - My card has been stolen. What should I do? | |
| - Why hasn’t the recipient received my transfer? | |
| """ | |
| # Define the Gradio interface | |
| interface = gr.Interface( | |
| fn=chatbot_response, | |
| inputs=gr.Textbox(lines=2, placeholder="Ask your fintech question here..."), | |
| outputs="text", | |
| title="FinTech Chatbot", | |
| description=description | |
| ) | |
| if __name__ == "__main__": | |
| # Launch the Gradio app | |
| interface.launch() |