walaa2022 commited on
Commit
5657ab6
Β·
verified Β·
1 Parent(s): a47787d

Update pages/she_melted_mascara.py

Browse files
Files changed (1) hide show
  1. 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. Use gentle, supportive Gen Z language.",
 
 
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
- model = genai.GenerativeModel('gemini-pro-vision')
42
- prompt = f"""As an empathetic art therapist for teens, analyze this drawing:
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
- model = genai.GenerativeModel('gemini-pro')
 
51
  prompt = f"{CATEGORIES[category]['prompt']}\nUser: {message}\nRespond with empathy and support:"
52
  response = model.generate_content(prompt)
53
- return response.text
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
- ["Keep private & get AI feedback", "Share with community"],
163
  key="art_share_option"
164
  )
165
 
166
- if st.button("πŸ’« Process Artwork"):
167
- if share_option == "Keep private & get AI feedback":
168
- # Add to private chat
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
- response = get_ai_response(None, category, image)
178
- st.session_state.chat_history[category].append({
179
- "role": "assistant",
180
- "content": response,
181
- "timestamp": datetime.now().strftime("%I:%M %p")
182
- })
183
- else:
184
- # Share with community
185
- st.session_state.community_posts.insert(0, {
186
- "category": category,
187
- "content": "Sharing my feelings through art...",
188
- "image": image,
189
- "timestamp": datetime.now().strftime("%I:%M %p"),
190
- "hugs": 0,
191
- "support": 0,
192
- "comments": []
193
- })
194
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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