jostlebot commited on
Commit
81fe2c9
Β·
1 Parent(s): 83fdf61

Update Streamlit app with working Claude API integration and improved UI

Browse files
Files changed (3) hide show
  1. .gitignore +5 -0
  2. requirements.txt +3 -2
  3. src/streamlit_app.py +122 -64
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .env
2
+ __pycache__/
3
+ *.pyc
4
+ venv/
5
+ .DS_Store
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  streamlit==1.31.1
2
- anthropic==0.8.1
3
- python-dotenv==1.1.0
 
 
1
  streamlit==1.31.1
2
+ anthropic==0.5.0
3
+ python-dotenv==1.0.0
4
+ httpx==0.24.1
src/streamlit_app.py CHANGED
@@ -14,7 +14,14 @@ st.set_page_config(
14
  )
15
 
16
  # Initialize Anthropic client
17
- anthropic = Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))
 
 
 
 
 
 
 
18
 
19
  # Initialize session state variables
20
  if 'messages' not in st.session_state:
@@ -26,68 +33,107 @@ if 'system_message' not in st.session_state:
26
 
27
  # Main page header
28
  st.title("Attachment Style Roleplay Simulator")
 
 
29
  st.markdown("""
30
- Welcome to the Attachment Style Roleplay Simulator! This tool helps you practice difficult conversations
31
- by simulating realistic relational dynamics based on your attachment style. You can explore how different
32
- approaches and communication styles might work in challenging situations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  """)
34
 
35
  # Sidebar welcome and introduction
36
  with st.sidebar:
37
- st.header("Welcome!")
38
  st.markdown("""
39
- Created by [Jocelyn Skillman LMHC](http://www.jocelynskillman.com), this tool is designed to help you
40
- practice and understand relational dynamics through the lens of attachment theory.
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- To learn more about attachment theory and therapeutic approaches, check out my newsletter:
43
- [@jocelynskillmanlmhc](https://jocelynskillmanlmhc.substack.com/)
 
 
 
 
 
 
 
44
  """)
 
 
 
 
45
 
46
- # Simulation setup form
47
- with st.form("setup_form"):
48
- st.subheader("Set Up Your Simulation")
49
-
50
- attachment_style = st.selectbox(
51
- "Select your attachment style:",
52
- ["Secure", "Anxious", "Avoidant", "Disorganized"]
53
- )
54
-
55
- scenario = st.text_area(
56
- "Describe the scenario you'd like to practice:",
57
- placeholder="Example: Having a difficult conversation with my partner about feeling disconnected"
58
- )
59
-
60
- tone = st.text_input(
61
- "How would you like the AI to respond?",
62
- placeholder="Example: Direct but understanding"
63
- )
 
 
 
 
 
 
 
 
 
64
 
65
- goals = st.text_area(
66
- "What are your practice goals?",
67
- placeholder="Example: Practice expressing needs without becoming defensive"
68
- )
69
 
70
- submitted = st.form_submit_button("Start Simulation")
 
71
 
72
- if submitted:
73
- # Prepare system message with simulation parameters
74
- st.session_state.system_message = f"""
75
- You are a conversational partner helping someone practice difficult conversations.
76
- The user has a {attachment_style} attachment style and wants to practice: {scenario}
77
-
78
- Respond in a {tone} manner. Help them achieve their goals: {goals}
79
-
80
- Maintain a realistic conversation while providing gentle guidance when needed.
81
- """
82
-
83
- # Reset message history
84
- st.session_state.messages = []
85
- st.session_state.setup_complete = True
86
- st.rerun()
87
 
88
  # Display status or chat interface
89
  if not st.session_state.setup_complete:
90
- st.info("Please complete the simulation setup in the sidebar to begin.")
91
  else:
92
  # Display chat history
93
  for message in st.session_state.messages:
@@ -106,23 +152,35 @@ else:
106
  # Get AI response
107
  with st.chat_message("assistant"):
108
  with st.spinner("Thinking..."):
109
- messages = [
110
- {"role": "system", "content": st.session_state.system_message}
111
- ] + st.session_state.messages
112
-
113
- response = anthropic.messages.create(
114
- model="claude-3-opus-20240229",
115
- max_tokens=1000,
116
- messages=messages
117
- )
118
-
119
- ai_response = response.content[0].text
120
- st.markdown(ai_response)
121
 
122
- # Add AI response to chat history
123
- st.session_state.messages.append(
124
- {"role": "assistant", "content": ai_response}
125
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  # Footer
128
  st.markdown("---")
 
14
  )
15
 
16
  # Initialize Anthropic client
17
+ api_key = os.getenv('ANTHROPIC_API_KEY')
18
+ if not api_key:
19
+ st.error("Please set your ANTHROPIC_API_KEY in the .env file")
20
+ st.stop()
21
+
22
+ c = Anthropic(
23
+ api_key=api_key,
24
+ )
25
 
26
  # Initialize session state variables
27
  if 'messages' not in st.session_state:
 
33
 
34
  # Main page header
35
  st.title("Attachment Style Roleplay Simulator")
36
+
37
+ # Welcome text in main content area
38
  st.markdown("""
39
+ Welcome!
40
+
41
+ Created by [Jocelyn Skillman LMHC](http://www.jocelynskillman.com), this tool is designed to help you practice and understand relational dynamics through the lens of attachment theory.
42
+
43
+ To learn more about attachment theory and therapeutic approaches, check out my newsletter: [@jocelynskillmanlmhc](https://jocelynskillmanlmhc.substack.com/)
44
+ """)
45
+
46
+ st.markdown("""
47
+ This specific project β€” the Attachment Roleplay Simulator β€” invites users to practice emotionally difficult conversations, like setting boundaries, through roleplay tailored to their attachment style. It's designed to help people feel into relational patterns, develop language for self-advocacy, and build nervous system capacity for connection and repair.
48
+
49
+ πŸ’‘ Not sure about your attachment style?
50
+ You can take the free quiz by Sarah Peyton β€” or simply choose the one that resonates when you read it:
51
+
52
+ Anxious – "I often worry I've upset people or need to explain myself."
53
+
54
+ Avoidant – "I'd rather deal with things alone and not depend on anyone."
55
+
56
+ Disorganized – "I want closeness, but also feel unsafe or mistrusting."
57
+
58
+ Secure – "I can express needs and handle conflict without losing connection."
59
+
60
+ Choose what vibes β€” this is a practice space, not a test.
61
  """)
62
 
63
  # Sidebar welcome and introduction
64
  with st.sidebar:
 
65
  st.markdown("""
66
+ Hi, I'm Jocelyn Skillman, LMHC β€” a clinical therapist, relational design ethicist, and creator of experimental tools that explore how AI can support (not replace) human care.
67
+
68
+ Each tool in this collection is thoughtfully designed to:
69
+
70
+ Extend therapeutic support between sessions
71
+
72
+ Model emotional safety and relational depth
73
+
74
+ Help clients and clinicians rehearse courage, regulation, and repair
75
+
76
+ Stay grounded in trauma-informed, developmentally sensitive frameworks
77
+ """)
78
+
79
+ st.divider()
80
 
81
+ # Add the moved content to the bottom of sidebar
82
+ st.markdown("""
83
+ I use Claude (by Anthropic) as the primary language model for these tools, chosen for its relational tone, contextual nuance, and responsiveness to emotionally complex prompts.
84
+
85
+ As a practicing therapist, I imagine these resources being especially helpful to clinicians like myself β€” companions in the work of tending to others with insight, warmth, and care.
86
+
87
+ To learn more about my work, visit:
88
+ 🌐 [jocelynskillman.com](http://www.jocelynskillman.com)
89
+ πŸ“¬ [Substack: Relational Code](https://jocelynskillmanlmhc.substack.com/)
90
  """)
91
+
92
+ # Simulation setup form
93
+ with st.form("setup_form"):
94
+ st.header("Set Up Your Simulation")
95
 
96
+ attachment_style = st.selectbox(
97
+ "Select your attachment style:",
98
+ ["Secure", "Anxious", "Avoidant", "Disorganized"]
99
+ )
100
+
101
+ scenario = st.text_area(
102
+ "Describe the scenario you'd like to practice:",
103
+ placeholder="Example: Having a difficult conversation with my partner about feeling disconnected"
104
+ )
105
+
106
+ tone = st.text_input(
107
+ "How would you like the AI to respond?",
108
+ placeholder="Example: Direct but understanding"
109
+ )
110
+
111
+ goals = st.text_area(
112
+ "What are your practice goals?",
113
+ placeholder="Example: Practice expressing needs without becoming defensive"
114
+ )
115
+
116
+ submitted = st.form_submit_button("Start Simulation")
117
+
118
+ if submitted:
119
+ # Prepare system message with simulation parameters
120
+ st.session_state.system_message = f"""
121
+ You are a conversational partner helping someone practice difficult conversations.
122
+ The user has a {attachment_style} attachment style and wants to practice: {scenario}
123
 
124
+ Respond in a {tone} manner. Help them achieve their goals: {goals}
 
 
 
125
 
126
+ Maintain a realistic conversation while providing gentle guidance when needed.
127
+ """
128
 
129
+ # Reset message history
130
+ st.session_state.messages = []
131
+ st.session_state.setup_complete = True
132
+ st.rerun()
 
 
 
 
 
 
 
 
 
 
 
133
 
134
  # Display status or chat interface
135
  if not st.session_state.setup_complete:
136
+ st.info("Please complete the simulation setup to begin.")
137
  else:
138
  # Display chat history
139
  for message in st.session_state.messages:
 
152
  # Get AI response
153
  with st.chat_message("assistant"):
154
  with st.spinner("Thinking..."):
155
+ # Construct conversation history
156
+ messages = []
157
+ if st.session_state.system_message:
158
+ messages.append({"role": "system", "content": st.session_state.system_message})
159
+ for msg in st.session_state.messages:
160
+ messages.append({"role": msg["role"], "content": msg["content"]})
 
 
 
 
 
 
161
 
162
+ # Get completion
163
+ try:
164
+ message = c.messages.create(
165
+ model="claude-3-opus-20240229",
166
+ max_tokens=1000,
167
+ system=st.session_state.system_message,
168
+ messages=[
169
+ {"role": msg["role"], "content": msg["content"]}
170
+ for msg in st.session_state.messages
171
+ ]
172
+ )
173
+
174
+ ai_response = message.content[0].text
175
+ st.markdown(ai_response)
176
+
177
+ # Add AI response to chat history
178
+ st.session_state.messages.append(
179
+ {"role": "assistant", "content": ai_response}
180
+ )
181
+ except Exception as e:
182
+ st.error(f"Error getting AI response: {str(e)}")
183
+ st.error("Please try again or contact support if the issue persists.")
184
 
185
  # Footer
186
  st.markdown("---")