nikesh66 commited on
Commit
c81d86f
·
1 Parent(s): a936c3b

Upload 3 files

Browse files
Files changed (3) hide show
  1. bank.db +0 -0
  2. life_insurer_data.db +0 -0
  3. streamlit_app.py +190 -0
bank.db ADDED
Binary file (24.6 kB). View file
 
life_insurer_data.db ADDED
Binary file (8.19 kB). View file
 
streamlit_app.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ col1, col2 = st.columns(2)
11
+ conn = sqlite3.connect('bank.db')
12
+ c = conn.cursor()
13
+
14
+ def chatbot():
15
+
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
+ with col1:
21
+
22
+ question_1 = "Do you want health insurance?"
23
+ options_1 = ["Yes", "No"]
24
+
25
+ st.write(question_1)
26
+ selected_option_1 = st.selectbox("Please enter your option:", options_1)
27
+ if selected_option_1 == "No":
28
+ st.write("Thank you")
29
+ image = Image.open('D:\alegria\one insurance\source\assets\img\thank you.jpg')
30
+ st.image(image, caption='Please visit again!')
31
+ return
32
+
33
+ question_2 = "Select the Institution from where you want the Insurance"
34
+ options_2 = ["Select something","Bank of Baroda", "State Bank of India(SBI)", "HDFC Bank", "LIC"]
35
+
36
+ st.subheader(question_2)
37
+ selected_option_2 = st.selectbox("Please enter your option:", options_2)
38
+
39
+ with col2:
40
+ if selected_option_2 == "Bank of Baroda":
41
+ st.image('https://1000logos.net/wp-content/uploads/2021/06/Bank-of-Baroda-logo.png')
42
+ elif selected_option_2 == "State Bank of India(SBI)":
43
+ st.image('https://1000logos.net/wp-content/uploads/2018/03/SBI-Logo.png')
44
+ elif selected_option_2 == "HDFC Bank":
45
+ st.image('https://1000logos.net/wp-content/uploads/2021/06/HDFC-Bank-logo.png')
46
+ elif selected_option_2 == "LIC":
47
+ st.image('https://1000logos.net/wp-content/uploads/2021/08/LIC-Logo.png')
48
+
49
+ # Get comprehensive information about the selected bank
50
+ comprehensive_info = openai.Completion.create(
51
+ engine="text-davinci-003",
52
+ prompt=f"Please provide comprehensive information about {selected_option_2}",
53
+ max_tokens=250,
54
+ n=1,
55
+ stop=None,
56
+ temperature=0.5,
57
+ ).choices[0].text
58
+ st.write("Comprehensive information:")
59
+ st.write(comprehensive_info)
60
+
61
+ with col1:
62
+ c.execute('SELECT Policy_Name FROM BANK WHERE Bank_Name= "{}"'.format(selected_option_2))
63
+ options_3 = c.fetchall()
64
+
65
+ # st.write(options_3)
66
+ my_options = []
67
+ for row in options_3:
68
+ my_options.append(row[0])
69
+
70
+ st.subheader("Select the Policy Name")
71
+ selected_option_3 = st.selectbox("Please enter your option:", my_options)
72
+ with col2:
73
+ c.execute('SELECT Policy_doc FROM BANK WHERE Policy_Name = "{}"'.format(selected_option_3))
74
+ policy_doc_link = c.fetchone()
75
+ # Get comprehensive information about the selected bank
76
+ info = openai.Completion.create(
77
+ engine="text-davinci-003",
78
+ prompt=f"Please provide comprehensive information about {selected_option_3}",
79
+ max_tokens=100,
80
+ n=1,
81
+ stop=None,
82
+ temperature=0.5,
83
+ ).choices[0].text
84
+ st.write("Information:")
85
+ st.write(info)
86
+ with col1:
87
+ st.write("Loading...")
88
+ # Add loading animation
89
+ bar = st.progress(0)
90
+ for i in range(100):
91
+ # Update the progress bar with each iteration
92
+ bar.progress(i + 1)
93
+ time.sleep(0.05)
94
+
95
+ st.write("") # add a newline after the loading bar
96
+ if selected_option_3 != None:
97
+ st.subheader("List of Questions")
98
+ question_list= """
99
+
100
+ 1. What is covered under the policy?
101
+ 2. What are the policy exclusions?
102
+ 3. What are the conditions to avail the benefits of the insurance policy?
103
+ 4. What is the policy deductible and how does it work?
104
+ 5. What is the policy's out-of-pocket maximum?
105
+ 6. What is the policy's co-pay amount?
106
+ 7. Is there a network of providers or can I see any doctor I choose?
107
+ 8. Are pre-existing conditions covered under the policy?
108
+ 9. What is the process for filing a claim?
109
+ 10. What is the policy's premium and how often is it due?
110
+ 11. How does the policy handle cost-sharing for prescription drugs?
111
+ 12. Are there any limits on the number of visits or treatments for a particular condition?
112
+ 13. Does the policy offer coverage for mental health services and rehabilitation?
113
+ """
114
+
115
+ st.write(question_list)
116
+ def switch_question(argument):
117
+ switch = {
118
+ 1: "What is covered under the policy?",
119
+ 2: "What are the policy exclusions?",
120
+ 3: "What are the conditions to avail the benefits of the insurance policy?",
121
+ 4: "What is the policy deductible and how does it work?",
122
+ 5: "What is the policy's out-of-pocket maximum?",
123
+ 6: "What is the policy's co-pay amount?",
124
+ 7: "Is there a network of providers or can I see any doctor I choose?",
125
+ 8: "Are pre-existing conditions covered under the policy?",
126
+ 9: "What is the process for filing a claim?",
127
+ 10: "What is the policy's premium and how often is it due?",
128
+ 11: "How does the policy handle cost-sharing for prescription drugs?",
129
+ 12: "Are there any limits on the number of visits or treatments for a particular condition?",
130
+ 13: "Does the policy offer coverage for mental health services and rehabilitation?"
131
+ }
132
+ return switch.get(argument, "Invalid Input")
133
+
134
+ question_number = st.number_input("Please select a question number", min_value=1, max_value=13)
135
+ selected_question = switch_question(question_number)
136
+ response = "Sorry, I cannot answer that."
137
+
138
+ if selected_question != "Invalid Input":
139
+ response = openai.Completion.create(
140
+ model="text-davinci-003",
141
+ prompt="Read the following PDF Document\n\n{}\n\nAnswer the question based on the document provided\n{}".format(policy_doc_link, selected_question),
142
+ temperature=0,
143
+ max_tokens=250,
144
+ top_p=1,
145
+ frequency_penalty=0.5,
146
+ presence_penalty=0,
147
+ stop=["?"]
148
+ )
149
+
150
+
151
+ message = response.choices[0].text
152
+ st.write(f"Answer: {message}")
153
+ else:
154
+ st.write(response)
155
+ with col2:
156
+ def fetch_data():
157
+ # connect to the database
158
+ conn1 = sqlite3.connect("life_insurer_data.db")
159
+
160
+ # create a cursor
161
+ cursor = conn1.cursor()
162
+
163
+ # fetch the data from the database
164
+ fetch_query = """
165
+ SELECT * FROM life_insurer_data;
166
+ """
167
+ cursor.execute(fetch_query)
168
+ data = cursor.fetchall()
169
+
170
+ # close the connection to the database
171
+ conn.close()
172
+
173
+ return data
174
+
175
+ # display the data in a table
176
+ st.title("Life Insurer Data")
177
+ st.write("Data Scrapped from https://freefincal.com/irda-life-insurance-claim-settlement-ratio-2023/")
178
+ st.write("Data fetched from SQLite database")
179
+
180
+ life_insurers = [row[0] for row in fetch_data()]
181
+ selected_life_insurer = st.selectbox("Select a life insurer", life_insurers)
182
+
183
+ with st.spinner("Fetching data..."):
184
+ time.sleep(2)
185
+ for row in fetch_data():
186
+ if row[0] == selected_life_insurer:
187
+ st.write(f"Claim Settlement Ratio for {row[0]}: {row[1]}")
188
+
189
+ if __name__ == '__main__':
190
+ chatbot()