Spaces:
Sleeping
Sleeping
cr
Browse files
chat.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
insurance_context = """
|
3 |
+
Insurance is a contract, represented by a policy, in which an individual or entity receives financial protection against losses.
|
4 |
+
Common types include life insurance, health insurance, auto insurance, and home insurance.
|
5 |
+
Life insurance provides a sum of money to beneficiaries upon the insured's death, while health insurance covers medical expenses.
|
6 |
+
Auto insurance offers protection against vehicle-related accidents and damages. Home insurance covers damages to one’s property.
|
7 |
+
"""
|
8 |
+
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
|
9 |
+
def ask_question(question, context=insurance_context):
|
10 |
+
# Use the model to answer the question based on the context
|
11 |
+
response = qa_pipeline({
|
12 |
+
'question': question,
|
13 |
+
'context': context
|
14 |
+
})
|
15 |
+
return response['answer']
|
16 |
+
|
17 |
+
def chat():
|
18 |
+
print("Hello! I'm your insurance Q&A chatbot. Ask me anything about insurance.")
|
19 |
+
while True:
|
20 |
+
user_input = input("You: ")
|
21 |
+
|
22 |
+
if user_input.lower() in ["exit", "quit"]:
|
23 |
+
print("Thank you for using the chatbot. Goodbye!")
|
24 |
+
break
|
25 |
+
answer = ask_question(user_input)
|
26 |
+
print("Bot:", answer)
|
27 |
+
chat()
|