summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authort.me/xtekky <98614666+xtekky@users.noreply.github.com>2023-05-01 22:19:07 +0200
committerGitHub <noreply@github.com>2023-05-01 22:19:07 +0200
commita25f5d44ecfc817be95e99a78e319cb2ab513847 (patch)
tree0871b63d198b8e13e804af4be2000cf5c6aacf42
parentUpdate FUNDING.yml (diff)
parentadded option to remove conversations (diff)
downloadgpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar.gz
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar.bz2
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar.lz
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar.xz
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.tar.zst
gpt4free-a25f5d44ecfc817be95e99a78e319cb2ab513847.zip
Diffstat (limited to '')
-rw-r--r--gui/streamlit_chat_app.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/gui/streamlit_chat_app.py b/gui/streamlit_chat_app.py
index 99e8428c..af3969e6 100644
--- a/gui/streamlit_chat_app.py
+++ b/gui/streamlit_chat_app.py
@@ -38,6 +38,17 @@ def save_conversations(conversations, current_conversation):
os.replace(temp_conversations_file, conversations_file)
+def delete_conversation(conversations, current_conversation):
+ for idx, conversation in enumerate(conversations):
+ conversations[idx] = current_conversation
+ break
+ conversations.remove(current_conversation)
+
+ temp_conversations_file = "temp_" + conversations_file
+ with open(temp_conversations_file, "wb") as f:
+ pickle.dump(conversations, f)
+
+ os.replace(temp_conversations_file, conversations_file)
def exit_handler():
print("Exiting, saving data...")
@@ -118,17 +129,22 @@ if search_query:
sidebar_header = f"Search Results ({len(conversations)})"
else:
- conversations = enumerate(st.session_state.conversations)
+ conversations = st.session_state.conversations
sidebar_header = "Conversation History"
# Sidebar
st.sidebar.header(sidebar_header)
-
-for idx, conversation in conversations:
- if st.sidebar.button(f"Conversation {idx + 1}: {conversation['user_inputs'][0]}", key=f"sidebar_btn_{idx}"):
+sidebar_col1, sidebar_col2 = st.sidebar.columns([5,1])
+for idx, conversation in enumerate(conversations):
+ if sidebar_col1.button(f"Conversation {idx + 1}: {conversation['user_inputs'][0]}", key=f"sidebar_btn_{idx}"):
st.session_state['selected_conversation'] = idx
st.session_state['current_conversation'] = conversation
-
+ if sidebar_col2.button('🗑️', key=f"sidebar_btn_delete_{idx}"):
+ if st.session_state['selected_conversation'] == idx:
+ st.session_state['selected_conversation'] = None
+ st.session_state['current_conversation'] = {'user_inputs': [], 'generated_responses': []}
+ delete_conversation(conversations, conversation)
+ st.experimental_rerun()
if st.session_state['selected_conversation'] is not None:
conversation_to_display = conversations[st.session_state['selected_conversation']]
else: