jostlebot commited on
Commit
5f61ab7
·
1 Parent(s): 03185df

Deploy Attachment Style Roleplay Simulator with updated requirements

Browse files
Files changed (2) hide show
  1. requirements.txt +3 -3
  2. src/streamlit_app.py +132 -0
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ streamlit==1.31.1
2
+ anthropic==0.18.1
3
+ python-dotenv==1.1.0
src/streamlit_app.py CHANGED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from anthropic import Anthropic
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # Configure page
10
+ st.set_page_config(
11
+ page_title="Attachment Style Roleplay Simulator",
12
+ page_icon="🗣️",
13
+ layout="wide"
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:
21
+ st.session_state.messages = []
22
+ if 'setup_complete' not in st.session_state:
23
+ st.session_state.setup_complete = False
24
+ if 'system_message' not in st.session_state:
25
+ st.session_state.system_message = ""
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:
94
+ with st.chat_message(message["role"]):
95
+ st.markdown(message["content"])
96
+
97
+ # Chat input
98
+ if prompt := st.chat_input("Type your message here..."):
99
+ # Add user message to chat history
100
+ st.session_state.messages.append({"role": "user", "content": prompt})
101
+
102
+ # Display user message
103
+ with st.chat_message("user"):
104
+ st.markdown(prompt)
105
+
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("---")
129
+ st.markdown(
130
+ "Created by [Jocelyn Skillman LMHC](http://www.jocelynskillman.com) | "
131
+ "Learn more: [@jocelynskillmanlmhc](https://jocelynskillmanlmhc.substack.com/)"
132
+ )