Simplify chat UX: fixed scrollable container, input at bottom
Browse files
app.py
CHANGED
|
@@ -91,103 +91,86 @@ def main():
|
|
| 91 |
if "question_only" not in st.session_state:
|
| 92 |
st.session_state.question_only = False
|
| 93 |
|
| 94 |
-
# Sidebar
|
| 95 |
-
with st.sidebar:
|
| 96 |
-
st.markdown("### 🪞 GSPT")
|
| 97 |
-
st.caption("Generating Safer Passages of Text")
|
| 98 |
-
|
| 99 |
-
st.markdown("---")
|
| 100 |
-
|
| 101 |
-
# Mode toggle
|
| 102 |
-
st.markdown("### Mode")
|
| 103 |
-
question_only = st.toggle(
|
| 104 |
-
"Question Only",
|
| 105 |
-
value=st.session_state.question_only,
|
| 106 |
-
help="When on, GSPT responds only with questions"
|
| 107 |
-
)
|
| 108 |
-
st.session_state.question_only = question_only
|
| 109 |
-
|
| 110 |
-
if question_only:
|
| 111 |
-
st.caption("*Only asking questions*")
|
| 112 |
-
else:
|
| 113 |
-
st.caption("*Brief reflections + questions*")
|
| 114 |
-
|
| 115 |
-
st.markdown("---")
|
| 116 |
-
|
| 117 |
-
st.markdown("### About")
|
| 118 |
-
st.markdown("""
|
| 119 |
-
Not therapy. Not a confidant.
|
| 120 |
-
|
| 121 |
-
aI generates text — warm, boundaried reflections that bridge back to human connection.
|
| 122 |
-
""")
|
| 123 |
-
|
| 124 |
-
st.markdown("---")
|
| 125 |
-
|
| 126 |
-
st.markdown("### Crisis")
|
| 127 |
-
st.markdown("**988** · **741741** · **911**")
|
| 128 |
-
|
| 129 |
-
st.markdown("---")
|
| 130 |
-
|
| 131 |
-
if st.button("Clear All", use_container_width=True):
|
| 132 |
-
st.session_state.messages = []
|
| 133 |
-
st.session_state.journal = ""
|
| 134 |
-
st.rerun()
|
| 135 |
-
|
| 136 |
# Check for API client
|
| 137 |
client = get_api_client()
|
| 138 |
if not client:
|
| 139 |
st.error("Please set ANTHROPIC_API_KEY in your environment or Hugging Face secrets.")
|
| 140 |
st.stop()
|
| 141 |
|
| 142 |
-
#
|
| 143 |
chat_col, journal_col = st.columns([3, 2])
|
| 144 |
|
|
|
|
| 145 |
with chat_col:
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
| 160 |
-
if prompt := st.chat_input("Share what's on your mind..."):
|
| 161 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 162 |
-
with st.chat_message("user"):
|
| 163 |
-
st.markdown(prompt)
|
| 164 |
-
|
| 165 |
-
with st.chat_message("assistant"):
|
| 166 |
-
with st.spinner(""):
|
| 167 |
-
response = generate_response(
|
| 168 |
-
client,
|
| 169 |
-
st.session_state.messages,
|
| 170 |
-
question_only=st.session_state.question_only
|
| 171 |
-
)
|
| 172 |
-
st.markdown(response)
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
| 175 |
|
|
|
|
| 176 |
with journal_col:
|
| 177 |
-
st.markdown("
|
| 178 |
-
st.caption("
|
|
|
|
|
|
|
| 179 |
|
| 180 |
journal_text = st.text_area(
|
| 181 |
-
"
|
| 182 |
value=st.session_state.journal,
|
| 183 |
-
height=
|
| 184 |
-
placeholder="Write freely here
|
| 185 |
label_visibility="collapsed"
|
| 186 |
)
|
| 187 |
st.session_state.journal = journal_text
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
if __name__ == "__main__":
|
|
|
|
| 91 |
if "question_only" not in st.session_state:
|
| 92 |
st.session_state.question_only = False
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
# Check for API client
|
| 95 |
client = get_api_client()
|
| 96 |
if not client:
|
| 97 |
st.error("Please set ANTHROPIC_API_KEY in your environment or Hugging Face secrets.")
|
| 98 |
st.stop()
|
| 99 |
|
| 100 |
+
# Two column layout
|
| 101 |
chat_col, journal_col = st.columns([3, 2])
|
| 102 |
|
| 103 |
+
# ==================== CHAT COLUMN ====================
|
| 104 |
with chat_col:
|
| 105 |
+
# Header with controls
|
| 106 |
+
header_col, toggle_col, clear_col = st.columns([3, 1, 1])
|
| 107 |
+
with header_col:
|
| 108 |
+
st.markdown("### 🪞 GSPT")
|
| 109 |
+
with toggle_col:
|
| 110 |
+
question_only = st.toggle("Q only", value=st.session_state.question_only)
|
| 111 |
+
st.session_state.question_only = question_only
|
| 112 |
+
with clear_col:
|
| 113 |
+
if st.button("Clear"):
|
| 114 |
+
st.session_state.messages = []
|
| 115 |
+
st.rerun()
|
| 116 |
+
|
| 117 |
+
st.divider()
|
| 118 |
+
|
| 119 |
+
# Chat container
|
| 120 |
+
chat_container = st.container(height=450)
|
| 121 |
+
|
| 122 |
+
with chat_container:
|
| 123 |
+
# Welcome if empty
|
| 124 |
+
if not st.session_state.messages:
|
| 125 |
+
st.markdown("*What's alive for you right now?*")
|
| 126 |
+
|
| 127 |
+
# Display conversation
|
| 128 |
+
for msg in st.session_state.messages:
|
| 129 |
+
if msg["role"] == "user":
|
| 130 |
+
st.markdown(f"**You:** {msg['content']}")
|
| 131 |
+
else:
|
| 132 |
+
st.markdown(f"**GSPT:** {msg['content']}")
|
| 133 |
+
st.markdown("") # spacing
|
| 134 |
+
|
| 135 |
+
# Input at bottom
|
| 136 |
+
st.divider()
|
| 137 |
+
prompt = st.text_input(
|
| 138 |
+
"Type here",
|
| 139 |
+
key="user_input",
|
| 140 |
+
placeholder="Share what's on your mind...",
|
| 141 |
+
label_visibility="collapsed"
|
| 142 |
+
)
|
| 143 |
|
| 144 |
+
if prompt:
|
|
|
|
| 145 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
response = generate_response(
|
| 148 |
+
client,
|
| 149 |
+
st.session_state.messages,
|
| 150 |
+
question_only=st.session_state.question_only
|
| 151 |
+
)
|
| 152 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 153 |
+
st.rerun()
|
| 154 |
|
| 155 |
+
# ==================== JOURNAL COLUMN ====================
|
| 156 |
with journal_col:
|
| 157 |
+
st.markdown("### 📓 Journal")
|
| 158 |
+
st.caption("Private notes — not sent anywhere")
|
| 159 |
+
|
| 160 |
+
st.divider()
|
| 161 |
|
| 162 |
journal_text = st.text_area(
|
| 163 |
+
"Journal",
|
| 164 |
value=st.session_state.journal,
|
| 165 |
+
height=450,
|
| 166 |
+
placeholder="Write freely here...",
|
| 167 |
label_visibility="collapsed"
|
| 168 |
)
|
| 169 |
st.session_state.journal = journal_text
|
| 170 |
|
| 171 |
+
# Footer
|
| 172 |
+
st.divider()
|
| 173 |
+
st.caption("Not therapy. Not a confidant. aI generates text that bridges back to human connection. | Crisis: **988** · **741741** · **911**")
|
| 174 |
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|