shukdevdatta123 commited on
Commit
cf32ae6
·
verified ·
1 Parent(s): e0e3d17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -20,11 +20,11 @@ if 'openai_api_key' not in st.session_state:
20
  st.session_state.openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key:", type="password",
21
  value=st.session_state.openai_api_key)
22
 
23
- # Add a text input for the username
24
- if 'username' not in st.session_state:
25
- st.session_state.username = ""
26
 
27
- st.session_state.username = st.sidebar.text_input("Enter your username:")
28
 
29
  # Initialize session state for messages
30
  if "messages" not in st.session_state:
@@ -68,16 +68,16 @@ def load_data(uploaded_files):
68
 
69
  # Function to save the conversation
70
  def save_conversation():
71
- if st.session_state.username:
72
  conversation_entry = {
73
- "username": st.session_state.username,
74
  "messages": st.session_state.messages
75
  }
76
  with open("conversations.json", "a") as f:
77
  json.dump(conversation_entry, f)
78
  f.write("\n")
79
  else:
80
- st.warning("Please enter a username before saving the conversation.")
81
 
82
  # Function to load previous conversations
83
  def load_conversations():
@@ -92,8 +92,8 @@ def load_conversations():
92
  st.error("Error decoding JSON from conversations file. Please check the file.")
93
  continue
94
 
95
- # Filter conversations based on the current username
96
- return [conv for conv in conversations if isinstance(conv, dict) and "username" in conv and conv["username"] == st.session_state.username]
97
  return []
98
 
99
  # Function to delete selected conversations
 
20
  st.session_state.openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key:", type="password",
21
  value=st.session_state.openai_api_key)
22
 
23
+ # Add a text input for the phone number
24
+ if 'phone_number' not in st.session_state:
25
+ st.session_state.phone_number = ""
26
 
27
+ st.session_state.phone_number = st.sidebar.text_input("Enter your phone number:")
28
 
29
  # Initialize session state for messages
30
  if "messages" not in st.session_state:
 
68
 
69
  # Function to save the conversation
70
  def save_conversation():
71
+ if st.session_state.phone_number:
72
  conversation_entry = {
73
+ "phone_number": st.session_state.phone_number,
74
  "messages": st.session_state.messages
75
  }
76
  with open("conversations.json", "a") as f:
77
  json.dump(conversation_entry, f)
78
  f.write("\n")
79
  else:
80
+ st.warning("Please enter a phone number before saving the conversation.")
81
 
82
  # Function to load previous conversations
83
  def load_conversations():
 
92
  st.error("Error decoding JSON from conversations file. Please check the file.")
93
  continue
94
 
95
+ # Filter conversations based on the current phone number
96
+ return [conv for conv in conversations if isinstance(conv, dict) and "phone_number" in conv and conv["phone_number"] == st.session_state.phone_number]
97
  return []
98
 
99
  # Function to delete selected conversations