SatyamSinghal commited on
Commit
e4df837
·
verified ·
1 Parent(s): 0c2af00

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ # Set your OpenAI API key
5
+ openai.api_key = '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'
6
+
7
+ # Function to get response from OpenAI API
8
+ def get_openai_response(prompt):
9
+ response = openai.Completion.create(
10
+ engine="text-davinci-003",
11
+ prompt=prompt,
12
+ max_tokens=150,
13
+ n=1,
14
+ stop=None,
15
+ temperature=0.7,
16
+ )
17
+ message = response.choices[0].text.strip()
18
+ return message
19
+
20
+ # Streamlit UI components
21
+ st.title("Insurance Policy Advisor Chatbot")
22
+ st.write("Hello! I'm here to assist you in finding the best insurance policies tailored to your needs.")
23
+
24
+ # Initialize session state for conversation history
25
+ if 'messages' not in st.session_state:
26
+ st.session_state.messages = []
27
+
28
+ # Display conversation history
29
+ for msg in st.session_state.messages:
30
+ st.chat_message(msg['role']).markdown(msg['content'])
31
+
32
+ # User input
33
+ user_input = st.chat_input("Ask me about insurance policies...")
34
+
35
+ if user_input:
36
+ # Display user's message
37
+ st.session_state.messages.append({"role": "user", "content": user_input})
38
+ st.chat_message("user").markdown(user_input)
39
+
40
+ # Generate chatbot's response
41
+ prompt = f"Suggest insurance policies based on the following query: {user_input}"
42
+ response = get_openai_response(prompt)
43
+
44
+ # Display chatbot's response
45
+ st.session_state.messages.append({"role": "assistant", "content": response})
46
+ st.chat_message("assistant").markdown(response)