File size: 15,562 Bytes
1f5d4e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import streamlit as st
from datetime import datetime
import os
import google.generativeai as genai
from dotenv import load_dotenv
from PIL import Image
import io

# Load environment variables
load_dotenv()
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))

# Define categories with their properties
CATEGORIES = {
    "πŸ’” Heartbreak Hotel": {
        "color": "#FFB6C1",
        "prompt": "You are an empathetic friend helping with heartbreak. Use gentle, supportive, Gen Z language.",
        "description": "Share your heart feels & get support πŸ’•"
    },
    "🏠 Family Tea": {
        "color": "#E6E6FA",
        "prompt": "You are a wise friend helping with family issues. Use understanding, Gen Z language.",
        "description": "Spill the family tea & get advice πŸ«‚"
    },
    "πŸ“š School Stress": {
        "color": "#98FB98",
        "prompt": "You are a supportive friend helping with school stress. Use encouraging, Gen Z language.",
        "description": "Academic pressure? Let's talk it out πŸ“"
    },
    "🧠 Mental Health": {
        "color": "#DDA0DD",
        "prompt": "You are a caring friend and art therapist helping with mental health. Use gentle, supportive Gen Z language.",
        "description": "Safe space for mental health chat & art sharing πŸ’­"
    }
}

def get_ai_response(message, category, image=None):
    """Get supportive response from Gemini"""
    try:
        if image:
            model = genai.GenerativeModel('gemini-pro-vision')
            prompt = f"""As an empathetic art therapist for teens, analyze this drawing:
            1. Describe the emotions expressed
            2. Note any significant elements or symbols
            3. Provide gentle, supportive feedback
            4. Ask a caring question about their feelings
            Use Gen Z friendly language and be very supportive."""
            response = model.generate_content([prompt, image])
        else:
            model = genai.GenerativeModel('gemini-pro')
            prompt = f"{CATEGORIES[category]['prompt']}\nUser: {message}\nRespond with empathy and support:"
            response = model.generate_content(prompt)
        return response.text
    except Exception as e:
        return "I'm here for you bestie! Let's try chatting again? πŸ’•"

def show_page():
    st.title("πŸ’§ She Melted Mascara")
    st.write("Your safe space to let it all out! No filter needed here bestie πŸ’•")

    # Initialize session states
    if 'current_category' not in st.session_state:
        st.session_state.current_category = None
    if 'chat_history' not in st.session_state:
        st.session_state.chat_history = {}
        for category in CATEGORIES:
            st.session_state.chat_history[category] = []
    if 'community_posts' not in st.session_state:
        st.session_state.community_posts = []
    if 'view' not in st.session_state:
        st.session_state.view = 'categories'

    # Layout
    col1, col2 = st.columns([1, 2])

    # Left Column Navigation
    with col1:
        st.markdown("### Choose Your Space πŸ’•")
        
        # Category buttons
        for category in CATEGORIES:
            if st.button(
                f"{category}\n{CATEGORIES[category]['description']}",
                key=f"cat_{category}",
                use_container_width=True
            ):
                st.session_state.current_category = category
                st.session_state.view = 'chat'
                st.rerun()

        # Community button
        if st.button("πŸ’• Community Board\nSee shared stories & support others", 
                    key="community", use_container_width=True):
            st.session_state.view = 'community'
            st.rerun()

    # Right Column Content
    with col2:
        if st.session_state.view == 'chat' and st.session_state.current_category:
            category = st.session_state.current_category
            
            # Category Header
            st.markdown(f"""
                <div style='background-color: {CATEGORIES[category]["color"]}40; 
                         padding: 15px; border-radius: 10px; margin-bottom: 20px;'>
                    <h3>{category}</h3>
                    <p>{CATEGORIES[category]["description"]}</p>
                </div>
            """, unsafe_allow_html=True)

            # Chat mode selection
            chat_mode = st.radio(
                "Choose your chat mode:",
                ["πŸ’­ Private Chat", "✨ Public Share"],
                horizontal=True
            )

            if chat_mode == "πŸ’­ Private Chat":
                # Mental Health category special features
                if category == "🧠 Mental Health":
                    tab1, tab2 = st.tabs(["πŸ’­ Chat", "🎨 Art Expression"])
                    
                    with tab1:
                        # Display chat history
                        for message in st.session_state.chat_history[category]:
                            with st.chat_message(message["role"]):
                                st.write(message["content"])
                                if "image" in message:
                                    st.image(message["image"])

                        # Chat input
                        if prompt := st.chat_input("Share your feelings..."):
                            # Add user message
                            st.session_state.chat_history[category].append({
                                "role": "user",
                                "content": prompt,
                                "timestamp": datetime.now().strftime("%I:%M %p")
                            })
                            
                            # Get AI response
                            response = get_ai_response(prompt, category)
                            st.session_state.chat_history[category].append({
                                "role": "assistant",
                                "content": response,
                                "timestamp": datetime.now().strftime("%I:%M %p")
                            })
                            st.rerun()

                    with tab2:
                        st.write("Express yourself through art 🎨")
                        uploaded_file = st.file_uploader(
                            "Upload your drawing",
                            type=['png', 'jpg', 'jpeg']
                        )
                        
                        if uploaded_file:
                            image = Image.open(uploaded_file)
                            st.image(image, caption="Your artwork")
                            
                            share_option = st.radio(
                                "Would you like to:",
                                ["Keep private & get AI feedback", "Share with community"],
                                key="art_share_option"
                            )
                            
                            if st.button("πŸ’« Process Artwork"):
                                if share_option == "Keep private & get AI feedback":
                                    # Add to private chat
                                    st.session_state.chat_history[category].append({
                                        "role": "user",
                                        "content": "I made this drawing to express my feelings...",
                                        "image": image,
                                        "timestamp": datetime.now().strftime("%I:%M %p")
                                    })
                                    
                                    # Get AI analysis
                                    response = get_ai_response(None, category, image)
                                    st.session_state.chat_history[category].append({
                                        "role": "assistant",
                                        "content": response,
                                        "timestamp": datetime.now().strftime("%I:%M %p")
                                    })
                                else:
                                    # Share with community
                                    st.session_state.community_posts.insert(0, {
                                        "category": category,
                                        "content": "Sharing my feelings through art...",
                                        "image": image,
                                        "timestamp": datetime.now().strftime("%I:%M %p"),
                                        "hugs": 0,
                                        "support": 0,
                                        "comments": []
                                    })
                                st.rerun()

                else:
                    # Regular chat interface for other categories
                    for message in st.session_state.chat_history[category]:
                        with st.chat_message(message["role"]):
                            st.write(message["content"])

                    if prompt := st.chat_input("Tell me what's on your mind..."):
                        # Add user message
                        st.session_state.chat_history[category].append({
                            "role": "user",
                            "content": prompt,
                            "timestamp": datetime.now().strftime("%I:%M %p")
                        })
                        
                        # Get AI response
                        response = get_ai_response(prompt, category)
                        st.session_state.chat_history[category].append({
                            "role": "assistant",
                            "content": response,
                            "timestamp": datetime.now().strftime("%I:%M %p")
                        })
                        st.rerun()

            else:  # Public Share mode
                with st.form(key=f"public_share_{category}"):
                    st.write("Share with the community πŸ’•")
                    share_text = st.text_area("Your story matters!")
                    
                    col1, col2 = st.columns(2)
                    with col1:
                        anonymous = st.checkbox("Stay anonymous", value=True)
                    with col2:
                        allow_comments = st.checkbox("Allow comments", value=True)
                    
                    if st.form_submit_button("Share πŸ’"):
                        if share_text:
                            # Get AI support message
                            support_msg = get_ai_response(share_text, category)
                            
                            # Add to community posts
                            st.session_state.community_posts.insert(0, {
                                "category": category,
                                "content": share_text,
                                "support_message": support_msg,
                                "timestamp": datetime.now().strftime("%I:%M %p"),
                                "anonymous": anonymous,
                                "allow_comments": allow_comments,
                                "hugs": 0,
                                "support": 0,
                                "comments": []
                            })
                            st.success("Thanks for sharing, bestie! πŸ’•")
                            st.rerun()

        elif st.session_state.view == 'community':
            st.markdown("### πŸ’• Community Board")
            
            # Filter options
            col1, col2 = st.columns([2, 1])
            with col1:
                filter_cat = st.selectbox(
                    "Filter by category",
                    ["All"] + list(CATEGORIES.keys())
                )
            with col2:
                sort_by = st.selectbox(
                    "Sort by",
                    ["Latest", "Most Support", "Most Hugs"]
                )

            # Sort posts
            posts = st.session_state.community_posts.copy()
            if sort_by == "Most Support":
                posts.sort(key=lambda x: x.get('support', 0), reverse=True)
            elif sort_by == "Most Hugs":
                posts.sort(key=lambda x: x.get('hugs', 0), reverse=True)

            # Display posts
            for idx, post in enumerate(posts):
                if filter_cat == "All" or filter_cat == post["category"]:
                    with st.container():
                        # Post content
                        st.markdown(f"""
                            <div style='background-color: {CATEGORIES[post["category"]]["color"]}40; 
                                     padding: 15px; border-radius: 10px; margin: 10px 0;'>
                                <p style='color: #666; font-size: 0.9em;'>
                                    {post["category"]} β€’ {"Anonymous" if post.get("anonymous", True) else "Someone"} β€’ {post["timestamp"]}
                                </p>
                                <p>{post["content"]}</p>
                            </div>
                        """, unsafe_allow_html=True)

                        # Display image if present
                        if "image" in post:
                            st.image(post["image"])

                        # Support message if present
                        if "support_message" in post:
                            st.info(post["support_message"])

                        # Interaction buttons
                        col1, col2, col3 = st.columns([1,1,2])
                        with col1:
                            if st.button(f"πŸ«‚ Hug ({post.get('hugs', 0)})", key=f"hug_{idx}"):
                                post['hugs'] = post.get('hugs', 0) + 1
                                st.rerun()
                        with col2:
                            if st.button(f"πŸ’ Support ({post.get('support', 0)})", key=f"support_{idx}"):
                                post['support'] = post.get('support', 0) + 1
                                st.rerun()
                        with col3:
                            if post.get('allow_comments', True):
                                with st.expander("πŸ’­ Comments"):
                                    # Display existing comments
                                    for comment in post.get('comments', []):
                                        st.write(f"Anonymous: {comment}")
                                    
                                    # Add new comment
                                    new_comment = st.text_input("Add a supportive comment", key=f"comment_{idx}")
                                    if st.button("Send πŸ’•", key=f"send_{idx}"):
                                        if new_comment:
                                            if 'comments' not in post:
                                                post['comments'] = []
                                            post['comments'].append(new_comment)
                                            st.rerun()

        else:
            st.markdown("""
                ### Welcome to Your Safe Space! πŸ’•
                Choose a category on the left to:
                - Chat privately with AI support
                - Share with the community
                - Give and receive support
                
                Remember: You're never alone here! πŸ«‚
            """)