File size: 2,100 Bytes
ce1ca5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import openai
import streamlit as st
import sqlite3
from PIL import Image
import time

openai.api_key = "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"
# Database Connection

conn = sqlite3.connect('bank.db')
c = conn.cursor()


def policyBot():
    st.title("Welcome to OneInsurance ChatBot")

    policy_doc_link = "https://www.hdfcergo.com/docs/default-source/downloads/policy-wordings/health/arogya-sanjeevani---a5-size---pw---hehi.pdf"
    st.write("Ask any question about the Health Insurance you selected")

    question_2 = "Select the Institution from where you want the Insurance"
    options_2 = ["Bank of Baroda", "State Bank of India(SBI)", "HDFC Bank", "LIC"]

    st.subheader(question_2)
    selected_option_2 = st.selectbox("Please enter your option:", options_2)



    c.execute('SELECT Policy_Name FROM BANK WHERE Bank_Name= "{}"'.format(selected_option_2))
    options_3 = c.fetchall()

        # st.write(options_3)
    my_options = []
    for row in options_3:
        my_options.append(row[0])

    st.subheader("Select the Policy Name")
    selected_option_3 = st.selectbox("Please enter your option:", my_options)
        
    c.execute('SELECT Policy_doc FROM BANK WHERE Policy_Name = "{}"'.format(selected_option_3))
    policy_doc_link = c.fetchone()


    user_question = st.text_input(
        "Enter some text πŸ‘‡",
        label_visibility="visible",
        disabled=False,
        placeholder="Please Enter your question here",
    )

    question_response = openai.Completion.create(
                    model="text-davinci-003",
                    prompt="Read the following PDF Document\n\n{}\n\nAnswer the question based on the document provided\n{}?".format(policy_doc_link, user_question),
                    temperature=0,
                    max_tokens=260,
                    top_p=1,
                    frequency_penalty=0.5,
                    presence_penalty=0,
                    stop=["?"]
    )
    
    user_answer = question_response.choices[0].text
    st.write(f"Answer: {user_answer}")



if __name__ == '__main__':
    policyBot()