jostlebot commited on
Commit
0088e95
·
1 Parent(s): d35165b

Update interface to chat-like format with clear submit button and conversation history

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +60 -24
src/streamlit_app.py CHANGED
@@ -424,16 +424,25 @@ st.markdown("""
424
  </div>
425
  """, unsafe_allow_html=True)
426
 
427
- # Journal input
428
  st.markdown("### Share what's on your heart...")
429
- journal_entry = st.text_area(
430
- "",
431
- height=200,
432
- key="journal_input",
433
- help="This is your space to reflect freely. Your words are not stored or saved unless you choose to save them."
434
- )
435
-
436
- if journal_entry:
 
 
 
 
 
 
 
 
 
437
  try:
438
  message = c.messages.create(
439
  model="claude-3-opus-20240229",
@@ -442,35 +451,62 @@ if journal_entry:
442
  messages=[{"role": "user", "content": journal_entry}]
443
  )
444
 
445
- st.markdown("### Reflection")
446
- reflection_text = f"{TONE_STYLES[selected_tone]['icon']} {TONE_STYLES[selected_tone]['prefix']}\n\n{message.content[0].text}"
447
- st.markdown(reflection_text)
 
 
 
 
448
 
449
- # Simple save option
450
- if st.button("💌 Save this reflection"):
451
- st.session_state.journal_entries.append({
452
- "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
453
- "tone": selected_tone,
454
- "content": journal_entry,
455
- "reflection": reflection_text
456
- })
457
- st.success("Reflection saved.")
458
 
459
  except Exception as e:
460
  st.error(f"Error getting reflection: {str(e)}")
461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  # Display saved reflections if any
463
  if st.session_state.journal_entries:
464
  with st.expander("📔 Your Saved Reflections", expanded=False):
465
  for entry in reversed(st.session_state.journal_entries):
 
 
 
 
 
466
  st.markdown(f"""
467
- **{entry['timestamp']}** - *{entry['tone']}*
468
 
469
  *Your reflection:*
470
- {entry['content']}
471
 
472
  *Response:*
473
- {entry['reflection']}
474
 
475
  ---
476
  """)
 
424
  </div>
425
  """, unsafe_allow_html=True)
426
 
427
+ # Journal input and chat interface
428
  st.markdown("### Share what's on your heart...")
429
+ col1, col2 = st.columns([4, 1])
430
+ with col1:
431
+ journal_entry = st.text_area(
432
+ "",
433
+ height=100,
434
+ key="journal_input",
435
+ help="Share your thoughts here. Press the 'Send' button or Ctrl+Enter to submit.",
436
+ placeholder="Type your reflection here..."
437
+ )
438
+ with col2:
439
+ submit = st.button("Send 💌", use_container_width=True)
440
+
441
+ # Initialize chat history in session state if it doesn't exist
442
+ if 'chat_history' not in st.session_state:
443
+ st.session_state.chat_history = []
444
+
445
+ if submit and journal_entry: # Only process if there's text and button is clicked
446
  try:
447
  message = c.messages.create(
448
  model="claude-3-opus-20240229",
 
451
  messages=[{"role": "user", "content": journal_entry}]
452
  )
453
 
454
+ # Add the new exchange to chat history
455
+ st.session_state.chat_history.append({
456
+ "user_message": journal_entry,
457
+ "ai_response": f"{TONE_STYLES[selected_tone]['icon']} {TONE_STYLES[selected_tone]['prefix']}\n\n{message.content[0].text}",
458
+ "tone": selected_tone,
459
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
460
+ })
461
 
462
+ # Clear the input area after sending
463
+ st.rerun()
 
 
 
 
 
 
 
464
 
465
  except Exception as e:
466
  st.error(f"Error getting reflection: {str(e)}")
467
 
468
+ # Display chat history in reverse chronological order
469
+ st.markdown("### Conversation")
470
+ for exchange in reversed(st.session_state.chat_history):
471
+ # User message in a light container
472
+ st.markdown("""
473
+ <div style="background-color: #F8F9FA; padding: 1rem; border-radius: 8px; margin: 0.5rem 0;">
474
+ <p style="color: #666666; margin-bottom: 0.5rem;"><em>You</em></p>
475
+ <p style="margin: 0;">{}</p>
476
+ </div>
477
+ """.format(exchange["user_message"]), unsafe_allow_html=True)
478
+
479
+ # AI response in a warm container
480
+ st.markdown("""
481
+ <div style="background-color: #FFF8F3; padding: 1rem; border-radius: 8px; margin: 0.5rem 0;">
482
+ <p style="color: #666666; margin-bottom: 0.5rem;"><em>NurtureNest • {}</em></p>
483
+ <p style="margin: 0;">{}</p>
484
+ </div>
485
+ """.format(exchange["tone"], exchange["ai_response"]), unsafe_allow_html=True)
486
+
487
+ # Save conversation button at the bottom
488
+ if st.session_state.chat_history:
489
+ if st.button("📥 Save this conversation"):
490
+ st.session_state.journal_entries.extend(st.session_state.chat_history)
491
+ st.success("Conversation saved to your journal.")
492
+
493
  # Display saved reflections if any
494
  if st.session_state.journal_entries:
495
  with st.expander("📔 Your Saved Reflections", expanded=False):
496
  for entry in reversed(st.session_state.journal_entries):
497
+ timestamp = entry.get("timestamp", "")
498
+ tone = entry.get("tone", "")
499
+ content = entry.get("user_message", entry.get("content", ""))
500
+ reflection = entry.get("ai_response", entry.get("reflection", ""))
501
+
502
  st.markdown(f"""
503
+ **{timestamp}** - *{tone}*
504
 
505
  *Your reflection:*
506
+ {content}
507
 
508
  *Response:*
509
+ {reflection}
510
 
511
  ---
512
  """)