# from transformers import pipeline # insurance_context = """ # Insurance is a contract, represented by a policy, in which an individual or entity receives financial protection against losses. # Common types include life insurance, health insurance, auto insurance, and home insurance. # Life insurance provides a sum of money to beneficiaries upon the insured's death, while health insurance covers medical expenses. # Auto insurance offers protection against vehicle-related accidents and damages. Home insurance covers damages to one’s property. # """ # qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") # def ask_question(question, context=insurance_context): # # Use the model to answer the question based on the context # response = qa_pipeline({ # 'question': question, # 'context': context # }) # return response['answer'] # def chat(): # print("Hello! I'm your insurance Q&A chatbot. Ask me anything about insurance.") # while True: # user_input = input("You: ") # if user_input.lower() in ["exit", "quit"]: # print("Thank you for using the chatbot. Goodbye!") # break # answer = ask_question(user_input) # print("Bot:", answer) # chat() # import streamlit as st # from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration # # Load BlenderBot model and tokenizer # model_name = "facebook/blenderbot-400M-distill" # tokenizer = BlenderbotTokenizer.from_pretrained(model_name) # model = BlenderbotForConditionalGeneration.from_pretrained(model_name) # # Function to generate a response from BlenderBot # def get_blenderbot_response(input_text): # inputs = tokenizer(input_text, return_tensors="pt") # reply_ids = model.generate(**inputs) # response = tokenizer.decode(reply_ids[0], skip_special_tokens=True) # return response # # Streamlit app # st.title("Insurance Q&A Chatbot") # st.write("Ask any question about insurance, and I'll do my best to help!") # # Chat history # if "history" not in st.session_state: # st.session_state.history = [] # # Input text box for user # user_input = st.text_input("You:", "") # # Respond to user input # if user_input: # # Add user question to history # st.session_state.history.append({"user": user_input}) # # Generate bot response # response = get_blenderbot_response(user_input) # st.session_state.history.append({"bot": response}) # # Display chat history # for message in st.session_state.history: # if "user" in message: # st.write("**You:**", message["user"]) # if "bot" in message: # st.write("**Bot:**", message["bot"]) # insurance_knowledge = { "What types of insurance do you offer?": "We offer auto, home, and life insurance policies.", "How do I file a claim?": "To file a claim, you can call our customer service line at 1-800-123-4567 or submit a claim form on our website.", "What is my policy coverage?": "Your policy details, including coverage limits and deductibles, can be found in your policy documents. If you need assistance, please contact our customer service team.", "What is the process for getting a quote?": "To get a quote, you can fill out our online quote form or speak with one of our licensed insurance agents." } # Define the Streamlit app st.title("Insurance Chatbot") user_input = st.text_area("You:", height=200) if st.button("Send"): if user_input.lower() in insurance_knowledge: st.text_area("Bot:", value=insurance_knowledge[user_input.lower()], height=200, max_chars=None, key=None) else: st.text_area("Bot:", value="I'm sorry, I don't have information on that topic. Please try rephrasing your question or contact our customer service team for assistance.", height=200, max_chars=None, key=None)