pratikshahp commited on
Commit
e626f8a
·
verified ·
1 Parent(s): aefe208

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import streamlit as st
2
  import openai
3
  import os
 
 
 
4
 
5
  # Set up OpenAI API key
6
  openai.api_key = os.getenv("OPENAI_API_KEY") # Replace with your OpenAI API key if not using an environment variable
@@ -23,7 +26,7 @@ st.title("Simple OpenAI Chatbot")
23
 
24
  # Initialize the chat history
25
  if "messages" not in st.session_state:
26
- st.session_state.messages = [{"role": "system", "content": "You are a helpful assistant. Reply in 20 words"}]
27
 
28
  # Display chat history
29
  for message in st.session_state.messages:
@@ -47,10 +50,6 @@ if st.button("Send"):
47
  # Add bot response to chat history
48
  st.session_state.messages.append({"role": "assistant", "content": bot_response})
49
 
50
- # Display updated chat history
51
- st.experimental_rerun()
52
-
53
  # Clear chat
54
  if st.button("Clear Chat"):
55
- st.session_state.messages = [{"role": "system", "content": "You are a helpful assistant. Reply in 20 words"}]
56
- st.experimental_rerun()
 
1
  import streamlit as st
2
  import openai
3
  import os
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv()
7
 
8
  # Set up OpenAI API key
9
  openai.api_key = os.getenv("OPENAI_API_KEY") # Replace with your OpenAI API key if not using an environment variable
 
26
 
27
  # Initialize the chat history
28
  if "messages" not in st.session_state:
29
+ st.session_state.messages = [{"role": "system", "content": "You are a helpful assistant. Respond in 20 words"}]
30
 
31
  # Display chat history
32
  for message in st.session_state.messages:
 
50
  # Add bot response to chat history
51
  st.session_state.messages.append({"role": "assistant", "content": bot_response})
52
 
 
 
 
53
  # Clear chat
54
  if st.button("Clear Chat"):
55
+ st.session_state.messages = [{"role": "system", "content": "You are a helpful assistant. Respond in 20 words"}]