Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from anthropic import Anthropic | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Configure Streamlit page settings | |
| st.set_page_config( | |
| page_title="Attachment Style Roleplay Simulator", | |
| page_icon="🎭", | |
| layout="centered", | |
| ) | |
| # Initialize Anthropic client | |
| anthropic = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY") or os.getenv("ANTHROPIC_KEY")) | |
| # Initialize session state for form inputs if not present | |
| if "setup_complete" not in st.session_state: | |
| st.session_state.setup_complete = False | |
| if "messages" not in st.session_state: | |
| st.session_state.messages = [] | |
| # Main page header | |
| st.markdown("<h1 style='text-align: center; color: #333;'>Attachment Style Roleplay Simulator</h1>", unsafe_allow_html=True) | |
| st.markdown("<p style='text-align: center; font-size: 18px; color: #555; margin-bottom: 1em;'>A Safe Space for Practicing Difficult Conversations</p>", unsafe_allow_html=True) | |
| # Welcome text and instructions | |
| if not st.session_state.setup_complete: | |
| st.markdown(""" | |
| ## Practice Hard Conversations—Safely. | |
| Welcome to a therapeutic roleplay simulator built for emotionally charged moments. | |
| This tool helps you rehearse boundary-setting and difficult conversations by simulating realistic relational dynamics—tailored to your attachment style. | |
| You'll choose: | |
| - A scenario (e.g., "Ask my mom not to comment on my body") | |
| - A tone of response (e.g., supportive, guilt-tripping, dismissive) | |
| - Your attachment style (e.g., anxious, avoidant, disorganized) | |
| - And your goal (e.g., "I want to stay calm and not backtrack") | |
| The AI will take on the role of a realistic human responder—not to therapize you, but to mirror the relational pressure you might encounter in real life. Then, you'll get a reflection summary to help you track your emotional patterns and practice courage. | |
| ### 🧠 Not sure what your attachment style is? | |
| You can take this [free quiz from Sarah Peyton](https://www.yourresonantself.com/attachment-assessment) to learn more. | |
| Or you can just pick the one that vibes when you read it: | |
| - **Anxious** – "I often worry if I've upset people or said too much." | |
| - **Avoidant** – "I'd rather handle things alone than depend on others." | |
| - **Disorganized** – "I want closeness, but I also feel overwhelmed or mistrusting." | |
| - **Secure** – "I can handle conflict and connection without losing myself." | |
| """) | |
| # Sidebar with setup form | |
| with st.sidebar: | |
| st.markdown(""" | |
| ### Welcome! 👋 | |
| 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. | |
| Each tool in this collection is thoughtfully designed to: | |
| - Extend therapeutic support between sessions | |
| - Model emotional safety and relational depth | |
| - Help clients and clinicians rehearse courage, regulation, and repair | |
| - Stay grounded in trauma-informed, developmentally sensitive frameworks | |
| 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. | |
| 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. | |
| #### Connect With Me | |
| 🌐 [jocelynskillman.com](http://www.jocelynskillman.com) | |
| 📬 [Substack: Relational Code](https://jocelynskillmanlmhc.substack.com/) | |
| --- | |
| """) | |
| st.markdown("### 🎯 Simulation Setup") | |
| with st.form("simulation_setup"): | |
| attachment_style = st.selectbox( | |
| "Your Attachment Style", | |
| ["Anxious", "Avoidant", "Disorganized", "Secure"], | |
| help="Select your attachment style for this practice session" | |
| ) | |
| scenario = st.text_area( | |
| "Scenario Description", | |
| placeholder="Example: I want to tell my dad I can't call every night anymore.", | |
| help="Describe the conversation you want to practice" | |
| ) | |
| tone = st.text_input( | |
| "Desired Tone for AI Response", | |
| placeholder="Example: guilt-tripping, dismissive, supportive", | |
| help="How should the AI character respond?" | |
| ) | |
| practice_goal = st.text_area( | |
| "Your Practice Goal", | |
| placeholder="Example: staying grounded and not over-explaining", | |
| help="What would you like to work on in this conversation?" | |
| ) | |
| submit_setup = st.form_submit_button("Start Simulation") | |
| if submit_setup and scenario and tone and practice_goal: | |
| # Create system message with simulation parameters | |
| system_message = f"""Attachment Style: {attachment_style} | |
| Scenario: {scenario} | |
| Tone: {tone} | |
| Goal: {practice_goal} | |
| Remember to stay in character unless the client says 'pause', 'reflect', or 'debrief'. | |
| Keep responses under 3 lines unless asked to elaborate.""" | |
| # Reset messages and add system message | |
| st.session_state.messages = [{"role": "assistant", "content": "Simulation ready. You can begin the conversation whenever you're ready."}] | |
| st.session_state.setup_complete = True | |
| st.rerun() | |
| # Display simulation status | |
| if not st.session_state.setup_complete: | |
| st.info("👈 Please complete the simulation setup in the sidebar to begin.") | |
| else: | |
| # Display chat history | |
| for message in st.session_state.messages: | |
| with st.chat_message(message["role"]): | |
| st.markdown(message["content"]) | |
| # User input field | |
| if user_prompt := st.chat_input("Type your message here... (or type 'debrief' to end simulation)"): | |
| # Add user message to chat history | |
| st.session_state.messages.append({"role": "user", "content": user_prompt}) | |
| # Display user message | |
| with st.chat_message("user"): | |
| st.markdown(user_prompt) | |
| # Get Claude's response | |
| with st.spinner("..."): | |
| response = anthropic.messages.create( | |
| model="claude-3-opus-20240229", | |
| max_tokens=1024, | |
| messages=[ | |
| {"role": m["role"], "content": m["content"]} | |
| for m in st.session_state.messages | |
| ] | |
| ) | |
| assistant_response = response.content[0].text | |
| # Add assistant response to chat history | |
| st.session_state.messages.append( | |
| {"role": "assistant", "content": assistant_response} | |
| ) | |
| # Display assistant response | |
| with st.chat_message("assistant"): | |
| st.markdown(assistant_response) | |
| # Footer | |
| st.markdown("---") | |
| st.markdown("<p style='text-align: center; font-size: 16px; color: #666;'>by <a href='http://www.jocelynskillman.com' target='_blank'>Jocelyn Skillman LMHC</a> - to learn more check out: <a href='https://jocelynskillmanlmhc.substack.com/' target='_blank'>jocelynskillmanlmhc.substack.com</a></p>", unsafe_allow_html=True) |