File size: 1,251 Bytes
999f39b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()