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()