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"""
{category}
{CATEGORIES[category]["description"]}
""", 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"""
{post["category"]} • {"Anonymous" if post.get("anonymous", True) else "Someone"} • {post["timestamp"]}
{post["content"]}
""", 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! 🫂
""")