AyushP's picture
Update app.py
ce483e6
import openai
import streamlit as st
import sqlite3
from PIL import Image
import pandas as pd
openai.api_key = "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"
# Database Connection
conn = sqlite3.connect('bank.db')
c = conn.cursor()
def policyCompare():
st.title("Compare Two Policy")
with st.container():
st.header("Select Policy 1")
question_2 = "Select the Institution from where you want the Insurance"
options_policy1 = ["Bank of Baroda", "State Bank of India(SBI)", "HDFC Bank", "LIC"]
st.subheader(question_2)
selected_option_policy1 = st.selectbox("Please enter your option for Policy 1:", options_policy1)
c.execute('SELECT Policy_Name FROM BANK WHERE Bank_Name= "{}"'.format(selected_option_policy1))
options_3 = c.fetchall()
my_options = []
for row in options_3:
my_options.append(row[0])
st.subheader("Select the Policy Name")
selected_policy1 = st.selectbox("Please enter your option for Policy 1:", my_options)
c.execute('SELECT Policy_doc FROM BANK WHERE Policy_Name = "{}"'.format(selected_policy1))
policy_doc_link1 = c.fetchone()
with st.container():
st.header("Select Policy 2")
question_2 = "Select the Institution from where you want the Insurance"
options_policy2 = ["Bank of Baroda", "State Bank of India(SBI)", "HDFC Bank", "LIC"]
st.subheader(question_2)
selected_option_policy2 = st.selectbox("Please enter your option for Policy 2:", options_policy2)
c.execute('SELECT Policy_Name FROM BANK WHERE Bank_Name= "{}"'.format(selected_option_policy2))
options_3 = c.fetchall()
# st.write(options_3)
my_options2 = []
for row in options_3:
my_options2.append(row[0])
st.subheader("Select the Policy Name")
selected_policy2 = st.selectbox("Please enter your option for Policy 2:", my_options2)
c.execute('SELECT Policy_doc FROM BANK WHERE Policy_Name = "{}"'.format(selected_policy1))
policy_doc_link2 = c.fetchone()
if(selected_policy2 != 0):
st.header("Comparison")
st.subheader("Policy 1 : {}".format(selected_policy1))
st.subheader("Policy 2 : {}".format(selected_policy2))
response = openai.Completion.create(
model="text-davinci-003",
prompt="Compare the two health insurance policy using the policy document\nPolicy 1 Document: {},\nPolicy 2 Document: {}\nStrictly show the answer in tabular format:-".format(policy_doc_link1, policy_doc_link2),
temperature=0.05,
max_tokens=300,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=[":-"]
)
compare_response = response.choices[0].text
st.write(f"Answer: {compare_response}")
if __name__ == '__main__':
policyCompare()