Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,17 @@ messages_dir = "messages"
|
|
| 7 |
if not os.path.exists(messages_dir):
|
| 8 |
os.makedirs(messages_dir)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Create a dictionary to store messages and threads
|
| 11 |
messages = {}
|
| 12 |
|
| 13 |
def create_thread(thread_id, user_input):
|
| 14 |
thread = {'messages': [user_input], 'created_at': datetime.now()}
|
| 15 |
messages[thread_id] = thread
|
|
|
|
| 16 |
|
| 17 |
def add_message(thread_id, user_input):
|
| 18 |
if thread_id in messages:
|
|
@@ -38,11 +43,11 @@ def main():
|
|
| 38 |
|
| 39 |
# Display existing threads
|
| 40 |
st.subheader("Existing Threads")
|
| 41 |
-
for thread_id in
|
| 42 |
st.write(f"- {thread_id}")
|
| 43 |
|
| 44 |
# Allow user to select a thread and add messages
|
| 45 |
-
thread_to_post = st.selectbox("Select a thread to post:",
|
| 46 |
if thread_to_post:
|
| 47 |
user_input = st.text_area("Write your message:", key='user_input')
|
| 48 |
if user_input:
|
|
|
|
| 7 |
if not os.path.exists(messages_dir):
|
| 8 |
os.makedirs(messages_dir)
|
| 9 |
|
| 10 |
+
# Initialize session state to store the list of threads
|
| 11 |
+
if 'thread_list' not in st.session_state:
|
| 12 |
+
st.session_state.thread_list = []
|
| 13 |
+
|
| 14 |
# Create a dictionary to store messages and threads
|
| 15 |
messages = {}
|
| 16 |
|
| 17 |
def create_thread(thread_id, user_input):
|
| 18 |
thread = {'messages': [user_input], 'created_at': datetime.now()}
|
| 19 |
messages[thread_id] = thread
|
| 20 |
+
st.session_state.thread_list.append(thread_id)
|
| 21 |
|
| 22 |
def add_message(thread_id, user_input):
|
| 23 |
if thread_id in messages:
|
|
|
|
| 43 |
|
| 44 |
# Display existing threads
|
| 45 |
st.subheader("Existing Threads")
|
| 46 |
+
for thread_id in st.session_state.thread_list:
|
| 47 |
st.write(f"- {thread_id}")
|
| 48 |
|
| 49 |
# Allow user to select a thread and add messages
|
| 50 |
+
thread_to_post = st.selectbox("Select a thread to post:", st.session_state.thread_list, key='thread_to_post')
|
| 51 |
if thread_to_post:
|
| 52 |
user_input = st.text_area("Write your message:", key='user_input')
|
| 53 |
if user_input:
|