Spaces:
Paused
Paused
Update app.py
Browse files
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
|
| 24 |
-
if '
|
| 25 |
-
st.session_state.
|
| 26 |
|
| 27 |
-
st.session_state.
|
| 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.
|
| 72 |
conversation_entry = {
|
| 73 |
-
"
|
| 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
|
| 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
|
| 96 |
-
return [conv for conv in conversations if isinstance(conv, dict) and "
|
| 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
|