Spaces:
Runtime error
Runtime error
Duplicate from nikesh66/policyai
Browse filesCo-authored-by: Nikesh Malik <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +147 -0
- bank.db +0 -0
- life_insurer_data.db +0 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Policyai
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.17.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: nikesh66/policyai
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import streamlit as st
|
3 |
+
import sqlite3
|
4 |
+
from PIL import Image
|
5 |
+
import time
|
6 |
+
|
7 |
+
openai.api_key = "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"
|
8 |
+
|
9 |
+
# Database Connection
|
10 |
+
|
11 |
+
conn = sqlite3.connect('bank.db')
|
12 |
+
c = conn.cursor()
|
13 |
+
|
14 |
+
|
15 |
+
def chatbot():
|
16 |
+
st.title("Welcome to OneInsurance")
|
17 |
+
|
18 |
+
policy_doc_link = "https://www.hdfcergo.com/docs/default-source/downloads/policy-wordings/health/arogya-sanjeevani---a5-size---pw---hehi.pdf"
|
19 |
+
|
20 |
+
question_1 = "Do you want health insurance?"
|
21 |
+
options_1 = ["Yes", "No"]
|
22 |
+
|
23 |
+
st.write(question_1)
|
24 |
+
selected_option_1 = st.selectbox("Please enter your option:", options_1)
|
25 |
+
if selected_option_1 == "No":
|
26 |
+
st.write("Thank you")
|
27 |
+
image = Image.open('thankyou.png')
|
28 |
+
st.image(image, caption='Please visit again!')
|
29 |
+
return
|
30 |
+
|
31 |
+
question_2 = "Select the Institution from where you want the Insurance"
|
32 |
+
options_2 = ["Bank of Baroda", "State Bank of India(SBI)", "HDFC Bank", "LIC"]
|
33 |
+
|
34 |
+
st.subheader(question_2)
|
35 |
+
selected_option_2 = st.selectbox("Please enter your option:", options_2)
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
c.execute('SELECT Policy_Name FROM BANK WHERE Bank_Name= "{}"'.format(selected_option_2))
|
40 |
+
options_3 = c.fetchall()
|
41 |
+
|
42 |
+
# st.write(options_3)
|
43 |
+
my_options = []
|
44 |
+
for row in options_3:
|
45 |
+
my_options.append(row[0])
|
46 |
+
|
47 |
+
st.subheader("Select the Policy Name")
|
48 |
+
selected_option_3 = st.selectbox("Please enter your option:", my_options)
|
49 |
+
|
50 |
+
c.execute('SELECT Policy_doc FROM BANK WHERE Policy_Name = "{}"'.format(selected_option_3))
|
51 |
+
policy_doc_link = c.fetchone()
|
52 |
+
|
53 |
+
# st.write(policy_doc_link)
|
54 |
+
st.subheader("List of Questions")
|
55 |
+
question_list= """
|
56 |
+
|
57 |
+
1. What is covered under the policy?
|
58 |
+
2. What are the policy exclusions?
|
59 |
+
3. What are the conditions to avail the benefits of the insurance policy?
|
60 |
+
4. What is the policy deductible and how does it work?
|
61 |
+
5. What is the policy's out-of-pocket maximum?
|
62 |
+
6. What is the policy's co-pay amount?
|
63 |
+
7. Is there a network of providers or can I see any doctor I choose?
|
64 |
+
8. Are pre-existing conditions covered under the policy?
|
65 |
+
9. What is the process for filing a claim?
|
66 |
+
10. What is the policy's premium and how often is it due?
|
67 |
+
11. How does the policy handle cost-sharing for prescription drugs?
|
68 |
+
12. Are there any limits on the number of visits or treatments for a particular condition?
|
69 |
+
13. Does the policy offer coverage for mental health services and rehabilitation?
|
70 |
+
"""
|
71 |
+
|
72 |
+
st.write(question_list)
|
73 |
+
def switch_question(argument):
|
74 |
+
switch = {
|
75 |
+
1: "What is covered under the policy?",
|
76 |
+
2: "What are the policy exclusions?",
|
77 |
+
3: "What are the conditions to avail the benefits of the insurance policy?",
|
78 |
+
4: "What is the policy deductible and how does it work?",
|
79 |
+
5: "What is the policy's out-of-pocket maximum?",
|
80 |
+
6: "What is the policy's co-pay amount?",
|
81 |
+
7: "Is there a network of providers or can I see any doctor I choose?",
|
82 |
+
8: "Are pre-existing conditions covered under the policy?",
|
83 |
+
9: "What is the process for filing a claim?",
|
84 |
+
10: "What is the policy's premium and how often is it due?",
|
85 |
+
11: "How does the policy handle cost-sharing for prescription drugs?",
|
86 |
+
12: "Are there any limits on the number of visits or treatments for a particular condition?",
|
87 |
+
13: "Does the policy offer coverage for mental health services and rehabilitation?"
|
88 |
+
}
|
89 |
+
return switch.get(argument, "Invalid Input")
|
90 |
+
|
91 |
+
question_number = st.number_input("Please select a question number", min_value=1, max_value=13)
|
92 |
+
selected_question = switch_question(question_number)
|
93 |
+
response = "Sorry, I cannot answer that."
|
94 |
+
|
95 |
+
if selected_question != "Invalid Input":
|
96 |
+
response = openai.Completion.create(
|
97 |
+
model="text-davinci-003",
|
98 |
+
prompt="Read the following PDF Document\n\n{}\n\nAnswer the question based on the document provided\n{}".format(policy_doc_link, selected_question),
|
99 |
+
temperature=0,
|
100 |
+
max_tokens=250,
|
101 |
+
top_p=1,
|
102 |
+
frequency_penalty=0.5,
|
103 |
+
presence_penalty=0,
|
104 |
+
stop=["?"]
|
105 |
+
)
|
106 |
+
|
107 |
+
|
108 |
+
message = response.choices[0].text
|
109 |
+
st.write(f"Answer: {message}")
|
110 |
+
else:
|
111 |
+
st.write(response)
|
112 |
+
|
113 |
+
def fetch_data():
|
114 |
+
# connect to the database
|
115 |
+
conn1 = sqlite3.connect("life_insurer_data.db")
|
116 |
+
|
117 |
+
# create a cursor
|
118 |
+
cursor = conn1.cursor()
|
119 |
+
|
120 |
+
# fetch the data from the database
|
121 |
+
fetch_query = """
|
122 |
+
SELECT * FROM life_insurer_data;
|
123 |
+
"""
|
124 |
+
cursor.execute(fetch_query)
|
125 |
+
data = cursor.fetchall()
|
126 |
+
|
127 |
+
# close the connection to the database
|
128 |
+
conn.close()
|
129 |
+
|
130 |
+
return data
|
131 |
+
|
132 |
+
# display the data in a table
|
133 |
+
st.title("Life Insurer Data")
|
134 |
+
st.write("Data Scrapped from https://freefincal.com/irda-life-insurance-claim-settlement-ratio-2023/")
|
135 |
+
st.write("Data fetched from SQLite database")
|
136 |
+
|
137 |
+
life_insurers = [row[0] for row in fetch_data()]
|
138 |
+
selected_life_insurer = st.selectbox("Select a life insurer", life_insurers)
|
139 |
+
|
140 |
+
with st.spinner("Fetching data..."):
|
141 |
+
time.sleep(2)
|
142 |
+
for row in fetch_data():
|
143 |
+
if row[0] == selected_life_insurer:
|
144 |
+
st.write(f"Claim Settlement Ratio for {row[0]}: {row[1]}")
|
145 |
+
|
146 |
+
if __name__ == '__main__':
|
147 |
+
chatbot()
|
bank.db
ADDED
Binary file (24.6 kB). View file
|
|
life_insurer_data.db
ADDED
Binary file (8.19 kB). View file
|
|