Spaces:
Running
Running
Update pages/she_melted_mascara.py
Browse files- pages/she_melted_mascara.py +179 -44
pages/she_melted_mascara.py
CHANGED
@@ -29,31 +29,125 @@ CATEGORIES = {
|
|
29 |
},
|
30 |
"π§ Mental Health": {
|
31 |
"color": "#DDA0DD",
|
32 |
-
"prompt": "You are a caring friend and art therapist helping with mental health.
|
|
|
|
|
33 |
"description": "Safe space for mental health chat & art sharing π"
|
34 |
}
|
35 |
}
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def get_ai_response(message, category, image=None):
|
38 |
"""Get supportive response from Gemini"""
|
39 |
try:
|
40 |
if image:
|
41 |
-
|
42 |
-
|
43 |
-
1. Describe the emotions expressed
|
44 |
-
2. Note any significant elements or symbols
|
45 |
-
3. Provide gentle, supportive feedback
|
46 |
-
4. Ask a caring question about their feelings
|
47 |
-
Use Gen Z friendly language and be very supportive."""
|
48 |
-
response = model.generate_content([prompt, image])
|
49 |
else:
|
50 |
-
|
|
|
51 |
prompt = f"{CATEGORIES[category]['prompt']}\nUser: {message}\nRespond with empathy and support:"
|
52 |
response = model.generate_content(prompt)
|
53 |
-
|
54 |
except Exception as e:
|
|
|
55 |
return "I'm here for you bestie! Let's try chatting again? π"
|
56 |
-
|
57 |
def show_page():
|
58 |
st.title("π§ She Melted Mascara")
|
59 |
st.write("Your safe space to let it all out! No filter needed here bestie π")
|
@@ -69,8 +163,7 @@ def show_page():
|
|
69 |
st.session_state.community_posts = []
|
70 |
if 'view' not in st.session_state:
|
71 |
st.session_state.view = 'categories'
|
72 |
-
|
73 |
-
# Layout
|
74 |
col1, col2 = st.columns([1, 2])
|
75 |
|
76 |
# Left Column Navigation
|
@@ -148,6 +241,7 @@ def show_page():
|
|
148 |
|
149 |
with tab2:
|
150 |
st.write("Express yourself through art π¨")
|
|
|
151 |
uploaded_file = st.file_uploader(
|
152 |
"Upload your drawing",
|
153 |
type=['png', 'jpg', 'jpeg']
|
@@ -155,43 +249,84 @@ def show_page():
|
|
155 |
|
156 |
if uploaded_file:
|
157 |
image = Image.open(uploaded_file)
|
158 |
-
st.image(image, caption="Your artwork")
|
159 |
|
160 |
share_option = st.radio(
|
161 |
"Would you like to:",
|
162 |
-
["
|
163 |
key="art_share_option"
|
164 |
)
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
st.session_state.chat_history[category].append({
|
170 |
-
"role": "user",
|
171 |
-
"content": "I made this drawing to express my feelings...",
|
172 |
-
"image": image,
|
173 |
-
"timestamp": datetime.now().strftime("%I:%M %p")
|
174 |
-
})
|
175 |
-
|
176 |
# Get AI analysis
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
|
196 |
else:
|
197 |
# Regular chat interface for other categories
|
|
|
29 |
},
|
30 |
"π§ Mental Health": {
|
31 |
"color": "#DDA0DD",
|
32 |
+
"prompt": """You are a caring friend and art therapist helping with mental health.
|
33 |
+
Use gentle, supportive Gen Z language. Focus on validation, understanding,
|
34 |
+
and providing resources when appropriate.""",
|
35 |
"description": "Safe space for mental health chat & art sharing π"
|
36 |
}
|
37 |
}
|
38 |
|
39 |
+
def get_art_analysis(image_data):
|
40 |
+
"""Get art analysis from Gemini Vision"""
|
41 |
+
try:
|
42 |
+
# Convert PIL Image to bytes
|
43 |
+
if isinstance(image_data, Image.Image):
|
44 |
+
img_byte_arr = io.BytesIO()
|
45 |
+
image_data.save(img_byte_arr, format='PNG')
|
46 |
+
img_byte_arr = img_byte_arr.getvalue()
|
47 |
+
else:
|
48 |
+
img_byte_arr = image_data
|
49 |
+
|
50 |
+
# Create vision model
|
51 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
52 |
+
|
53 |
+
# Prepare the image for analysis
|
54 |
+
image_parts = [
|
55 |
+
{
|
56 |
+
"mime_type": "image/png",
|
57 |
+
"data": img_byte_arr
|
58 |
+
}
|
59 |
+
]
|
60 |
+
|
61 |
+
prompt = """You are an empathetic art therapist analyzing artwork.
|
62 |
+
Provide a detailed, caring analysis using Gen Z language and emojis.
|
63 |
+
|
64 |
+
Please analyze:
|
65 |
+
1. π¨ Colors & Vibes
|
66 |
+
- What emotions do the colors give off?
|
67 |
+
- What's the overall mood?
|
68 |
+
|
69 |
+
2. π« Art Elements
|
70 |
+
- What catches your eye?
|
71 |
+
- What might these elements mean emotionally?
|
72 |
+
|
73 |
+
3. π Emotional Support
|
74 |
+
- Validate the feelings you see
|
75 |
+
- Share some encouraging words
|
76 |
+
|
77 |
+
4. π Growth & Reflection
|
78 |
+
- Ask a gentle question about their feelings
|
79 |
+
- Suggest a supportive activity
|
80 |
+
|
81 |
+
Use caring, relatable language that teens connect with."""
|
82 |
+
|
83 |
+
# Generate content
|
84 |
+
response = model.generate_content([prompt, image_parts[0]])
|
85 |
+
|
86 |
+
return response.text
|
87 |
+
|
88 |
+
except Exception as e:
|
89 |
+
print(f"Error in art analysis: {str(e)}")
|
90 |
+
return """I couldn't fully analyze your art bestie, but I'm here to support you! π
|
91 |
+
Would you like to tell me more about what you created? I'm all ears! β¨"""
|
92 |
+
|
93 |
+
# Add this function alongside your existing get_art_analysis function
|
94 |
+
def get_art_analysis(image_data):
|
95 |
+
"""Get art analysis from Gemini Vision"""
|
96 |
+
try:
|
97 |
+
# Convert PIL Image to bytes
|
98 |
+
if isinstance(image_data, Image.Image):
|
99 |
+
img_byte_arr = io.BytesIO()
|
100 |
+
image_data.save(img_byte_arr, format='PNG')
|
101 |
+
img_byte_arr = img_byte_arr.getvalue()
|
102 |
+
else:
|
103 |
+
img_byte_arr = image_data
|
104 |
+
|
105 |
+
# Create vision model
|
106 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
107 |
+
|
108 |
+
# Prepare the image for analysis
|
109 |
+
image_parts = [
|
110 |
+
{
|
111 |
+
"mime_type": "image/png",
|
112 |
+
"data": img_byte_arr
|
113 |
+
}
|
114 |
+
]
|
115 |
+
|
116 |
+
prompt = """You are an empathetic art therapist analyzing artwork.
|
117 |
+
Provide a caring analysis using Gen Z language and emojis.
|
118 |
+
|
119 |
+
π¨ Art Analysis:
|
120 |
+
- What emotions and mood do you see in this art?
|
121 |
+
- What catches your eye and what might it mean?
|
122 |
+
- Share some supportive and encouraging words
|
123 |
+
|
124 |
+
Keep your response caring and supportive, using language teens can relate to."""
|
125 |
+
|
126 |
+
# Generate content
|
127 |
+
response = model.generate_content([prompt, image_parts[0]])
|
128 |
+
|
129 |
+
return response.text
|
130 |
+
|
131 |
+
except Exception as e:
|
132 |
+
print(f"Error in art analysis: {str(e)}")
|
133 |
+
return """I couldn't fully analyze your art bestie, but I'm here to support you! π
|
134 |
+
Would you like to tell me more about what you created? I'm all ears! β¨"""
|
135 |
def get_ai_response(message, category, image=None):
|
136 |
"""Get supportive response from Gemini"""
|
137 |
try:
|
138 |
if image:
|
139 |
+
# If image is provided, use art analysis instead
|
140 |
+
return get_art_analysis(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
else:
|
142 |
+
# Regular chat response
|
143 |
+
model = genai.GenerativeModel('gemini-pro') # Note: Using stable version
|
144 |
prompt = f"{CATEGORIES[category]['prompt']}\nUser: {message}\nRespond with empathy and support:"
|
145 |
response = model.generate_content(prompt)
|
146 |
+
return response.text
|
147 |
except Exception as e:
|
148 |
+
print(f"Error in get_ai_response: {str(e)}")
|
149 |
return "I'm here for you bestie! Let's try chatting again? π"
|
150 |
+
|
151 |
def show_page():
|
152 |
st.title("π§ She Melted Mascara")
|
153 |
st.write("Your safe space to let it all out! No filter needed here bestie π")
|
|
|
163 |
st.session_state.community_posts = []
|
164 |
if 'view' not in st.session_state:
|
165 |
st.session_state.view = 'categories'
|
166 |
+
# Layout
|
|
|
167 |
col1, col2 = st.columns([1, 2])
|
168 |
|
169 |
# Left Column Navigation
|
|
|
241 |
|
242 |
with tab2:
|
243 |
st.write("Express yourself through art π¨")
|
244 |
+
st.write("Share your artwork and get supportive analysis β¨")
|
245 |
uploaded_file = st.file_uploader(
|
246 |
"Upload your drawing",
|
247 |
type=['png', 'jpg', 'jpeg']
|
|
|
249 |
|
250 |
if uploaded_file:
|
251 |
image = Image.open(uploaded_file)
|
252 |
+
st.image(image, caption="Your artwork π¨")
|
253 |
|
254 |
share_option = st.radio(
|
255 |
"Would you like to:",
|
256 |
+
["Get private analysis β¨", "Share with community π"],
|
257 |
key="art_share_option"
|
258 |
)
|
259 |
|
260 |
+
|
261 |
+
if st.button("β¨ Analyze My Art"):
|
262 |
+
with st.spinner("Analyzing your artwork with care and empathy... π«"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
# Get AI analysis
|
264 |
+
analysis = get_ai_response(None, category, image)
|
265 |
+
|
266 |
+
if share_option == "Get private analysis β¨":
|
267 |
+
# Display analysis directly
|
268 |
+
st.markdown("### π¨ Art Analysis")
|
269 |
+
st.markdown(analysis)
|
270 |
+
|
271 |
+
# Add to chat history
|
272 |
+
st.session_state.chat_history[category].append({
|
273 |
+
"role": "user",
|
274 |
+
"content": "I created this artwork to express my feelings...",
|
275 |
+
"image": image,
|
276 |
+
"timestamp": datetime.now().strftime("%I:%M %p")
|
277 |
+
})
|
278 |
+
|
279 |
+
st.session_state.chat_history[category].append({
|
280 |
+
"role": "assistant",
|
281 |
+
"content": analysis,
|
282 |
+
"timestamp": datetime.now().strftime("%I:%M %p")
|
283 |
+
})
|
284 |
+
|
285 |
+
# Simple follow-up option
|
286 |
+
if st.button("Share more about your art? π«"):
|
287 |
+
st.markdown("I'd love to hear more about what inspired this piece! What were you feeling while creating it? π")
|
288 |
+
|
289 |
+
else: # Share with community
|
290 |
+
# Add to community posts
|
291 |
+
st.session_state.community_posts.insert(0, {
|
292 |
+
"category": category,
|
293 |
+
"content": "Expressing my feelings through art...",
|
294 |
+
"image": image,
|
295 |
+
"support_message": analysis,
|
296 |
+
"timestamp": datetime.now().strftime("%I:%M %p"),
|
297 |
+
"hugs": 0,
|
298 |
+
"support": 0,
|
299 |
+
"comments": []
|
300 |
+
})
|
301 |
+
st.success("Thank you for sharing your art! The community is here for you π")
|
302 |
+
|
303 |
+
# Follow-up options
|
304 |
+
st.markdown("### Would you like to... π")
|
305 |
+
col1, col2 = st.columns(2)
|
306 |
+
with col1:
|
307 |
+
if st.button("Share more about this π«"):
|
308 |
+
followup_msg = "I'm here to listen and understand. Would you like to tell me more about what inspired this artwork? π"
|
309 |
+
st.session_state.chat_history[category].append({
|
310 |
+
"role": "assistant",
|
311 |
+
"content": followup_msg,
|
312 |
+
"timestamp": datetime.now().strftime("%I:%M %p")
|
313 |
+
})
|
314 |
+
st.markdown(followup_msg)
|
315 |
+
|
316 |
+
with col2:
|
317 |
+
if st.button("Get support tips π"):
|
318 |
+
support_msg = get_ai_response(
|
319 |
+
"Based on this artwork, what helpful coping strategies would you suggest?",
|
320 |
+
category
|
321 |
+
)
|
322 |
+
st.session_state.chat_history[category].append({
|
323 |
+
"role": "assistant",
|
324 |
+
"content": support_msg,
|
325 |
+
"timestamp": datetime.now().strftime("%I:%M %p")
|
326 |
+
})
|
327 |
+
st.markdown(support_msg)
|
328 |
+
|
329 |
+
|
330 |
|
331 |
else:
|
332 |
# Regular chat interface for other categories
|