sunbal7 commited on
Commit
44faf53
ยท
verified ยท
1 Parent(s): d435f6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +215 -89
app.py CHANGED
@@ -4,132 +4,258 @@ from groq import Groq
4
  from textblob import TextBlob
5
  import re
6
  import time
 
 
 
7
 
8
  # Initialize Groq client
9
  client = Groq(api_key=st.secrets["GROQ_API_KEY"])
10
 
11
  # Configure Streamlit
12
- st.set_page_config(page_title="๐Ÿคฃ Roast Master Therapist", layout="wide")
13
 
14
- # Custom CSS for animations
15
  st.markdown("""
16
  <style>
17
- @keyframes laugh {
18
- 0% { transform: scale(1); }
19
- 50% { transform: scale(1.2); }
20
- 100% { transform: scale(1); }
21
  }
22
 
23
- .laugh-emoji {
24
- animation: laugh 0.5s ease-in-out infinite;
25
- font-size: 3em;
26
  text-align: center;
27
  }
28
 
29
  .progress-bar {
30
- height: 20px;
31
- border-radius: 10px;
32
- background: #ff4b4b;
33
- transition: width 0.5s ease-in-out;
 
 
 
 
 
 
 
 
34
  }
35
  </style>
36
  """, unsafe_allow_html=True)
37
 
38
- def analyze_cbt(text):
39
- """Analyze text for cognitive distortions using CBT principles"""
 
 
 
 
 
 
 
40
  analysis = {
41
- 'absolutes': len(re.findall(r'\b(always|never|everyone|nobody)\b', text, re.I)),
42
- 'negative_words': TextBlob(text).sentiment.polarity,
43
- 'resilience_score': 100 # Start with perfect score
 
44
  }
45
 
46
- # Deduct points for cognitive distortions
47
- analysis['resilience_score'] -= analysis['absolutes'] * 5
48
- analysis['resilience_score'] = max(analysis['resilience_score'], 0)
 
 
49
 
 
 
50
  return analysis
51
 
52
- def generate_roast(prompt):
53
- """Generate a humorous roast using Groq/Mixtral"""
54
- system_prompt = """You are a sarcastic therapist who roasts bad habits in a funny way.
55
- Respond with 1-2 short sentences including emojis. Example: "Ah, the art of doing nothing!
56
- Do you charge Netflix for your couch imprint? ๐Ÿ›‹๏ธ" """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
 
 
 
58
  response = client.chat.completions.create(
59
  model="mixtral-8x7b-32768",
60
  messages=[
61
- {"role": "system", "content": system_prompt},
 
62
  {"role": "user", "content": prompt}
63
  ],
64
- temperature=0.9,
65
- max_tokens=100
66
  )
67
  return response.choices[0].message.content
68
 
69
- def get_cbt_tips(analysis):
70
- """Generate personalized CBT tips"""
71
- tips = []
72
- if analysis['absolutes'] > 0:
73
- tips.append("๐Ÿ” Notice absolute words like 'always/never' - reality is usually more nuanced!")
74
- if analysis['negative_words'] < -0.2:
75
- tips.append("๐ŸŒˆ Try reframing negative statements: 'I sometimes...' instead of 'I never...'")
76
- if analysis['resilience_score'] < 70:
77
- tips.append("๐Ÿ’ช Practice thought challenging: 'Is this truly catastrophic or just inconvenient?'")
78
- return tips
79
-
80
- # Main app interface
81
- st.title("๐Ÿคฃ Roast Master Therapist")
82
- st.markdown("### Your hilarious path to emotional resilience!")
83
-
84
- user_input = st.text_input("Share your problem or bad habit:",
85
- placeholder="e.g., 'I always procrastinate...'")
86
-
87
- if user_input:
88
- with st.spinner("Consulting the comedy gods..."):
89
- # Show laughing animation
90
- st.markdown('<div class="laugh-emoji">๐Ÿ˜‚</div>', unsafe_allow_html=True)
91
- time.sleep(1.5)
92
-
93
- # Generate and display roast
94
- roast = generate_roast(user_input)
95
- st.subheader("๐Ÿ”ฅ Your Roast:")
96
- st.write(roast)
97
-
98
- # Analyze and show results
99
- analysis = analyze_cbt(user_input)
100
- st.divider()
101
-
102
- # Resilience score visualization
103
- st.subheader("๐Ÿง  Resilience Analysis")
104
- score = analysis['resilience_score']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  st.markdown(f"""
106
- <div style="background: #f0f2f6; border-radius: 10px; padding: 10px;">
107
- <div class="progress-bar" style="width: {score}%;"></div>
108
- </div>
109
- <br>Current Resilience Score: {score}/100
110
- """, unsafe_allow_html=True)
111
 
112
- # Display CBT tips
113
- st.subheader("๐Ÿ’ก Growth Tips")
114
- for tip in get_cbt_tips(analysis):
115
- st.markdown(f"- {tip}")
116
-
117
- # Add disclaimer
118
- st.divider()
119
- st.caption("Disclaimer: This is not real therapy - it's therapy with jokes! Always consult a professional for serious concerns.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
- # Sidebar information
122
  with st.sidebar:
123
- st.header("How It Works")
124
  st.markdown("""
125
- 1. Share your bad habit/problem
126
- 2. Get hilariously roasted ๐Ÿคฃ
127
- 3. Receive psychological insights
128
- 4. Get personalized growth tips
 
 
129
 
130
- **Psychological Basis:**
131
- - Cognitive Behavioral Therapy (CBT)
132
- - Humor as emotional distancing
133
- - Positive reframing techniques
 
134
  """)
135
- st.image("https://i.imgur.com/7Q4X4yN.png", width=200)
 
4
  from textblob import TextBlob
5
  import re
6
  import time
7
+ from reportlab.lib.pagesizes import letter
8
+ from reportlab.pdfgen import canvas
9
+ import io
10
 
11
  # Initialize Groq client
12
  client = Groq(api_key=st.secrets["GROQ_API_KEY"])
13
 
14
  # Configure Streamlit
15
+ st.set_page_config(page_title="๐Ÿคฃ Roast Master Pro", layout="wide", page_icon="๐Ÿค–")
16
 
17
+ # Custom CSS
18
  st.markdown("""
19
  <style>
20
+ @keyframes float {
21
+ 0% { transform: translateY(0px); }
22
+ 50% { transform: translateY(-20px); }
23
+ 100% { transform: translateY(0px); }
24
  }
25
 
26
+ .emoji-float {
27
+ animation: float 3s ease-in-out infinite;
28
+ font-size: 2.5em;
29
  text-align: center;
30
  }
31
 
32
  .progress-bar {
33
+ height: 25px;
34
+ border-radius: 15px;
35
+ background: linear-gradient(90deg, #FF6B6B 0%, #FFE66D 100%);
36
+ transition: width 0.8s ease-in-out;
37
+ }
38
+
39
+ .stButton>button {
40
+ background: #4CAF50 !important;
41
+ color: white !important;
42
+ border-radius: 25px !important;
43
+ padding: 10px 25px !important;
44
+ font-size: 1.1em !important;
45
  }
46
  </style>
47
  """, unsafe_allow_html=True)
48
 
49
+ # Personality questions
50
+ QUESTIONS = [
51
+ {"text": "What's your most 'creative' excuse for procrastinating? ๐Ÿง ๐Ÿ’ค", "type": "funny"},
52
+ {"text": "How do you typically react when things don't go as planned? ๐ŸŒ€", "type": "serious"},
53
+ {"text": "Describe your ideal day... if adulting didn't exist ๐Ÿ–๏ธ๐Ÿน", "type": "funny"},
54
+ {"text": "What's one thing you'd change about your daily habits? ๐Ÿ”„", "type": "serious"}
55
+ ]
56
+
57
+ def analyze_personality(responses):
58
  analysis = {
59
+ 'humor_score': 0,
60
+ 'resilience': 100,
61
+ 'absolutes': 0,
62
+ 'negativity': 0
63
  }
64
 
65
+ for response in responses:
66
+ blob = TextBlob(response)
67
+ analysis['humor_score'] += len(re.findall(r'๐Ÿ˜‚|๐Ÿคฃ|๐Ÿ˜œ', response)) * 5
68
+ analysis['negativity'] += blob.sentiment.polarity
69
+ analysis['absolutes'] += len(re.findall(r'\b(always|never|everyone|nobody)\b', response, re.I))
70
 
71
+ analysis['resilience'] -= analysis['absolutes'] * 3
72
+ analysis['resilience'] = max(min(analysis['resilience'], 100), 0)
73
  return analysis
74
 
75
+ def generate_personality_report(analysis):
76
+ report = {
77
+ 'type': "",
78
+ 'strengths': [],
79
+ 'tips': [],
80
+ 'quote': ""
81
+ }
82
+
83
+ if analysis['humor_score'] > 15:
84
+ report['type'] = "The Resilient Jester ๐Ÿƒ"
85
+ report['strengths'] = ["Stress diffuser", "Creative thinker"]
86
+ report['tips'] = [
87
+ "๐ŸŽฏ Use humor to reframe challenges",
88
+ "๐Ÿง˜โ™‚๏ธ Balance jokes with mindfulness",
89
+ "๐Ÿ“… Schedule 'serious time' daily",
90
+ "๐ŸŽญ Channel creativity productively",
91
+ "๐Ÿค” Challenge 'all-or-nothing' thoughts",
92
+ "๐Ÿ“ Journal funny observations",
93
+ "๐ŸŒ… Start day with positive affirmation",
94
+ "๐ŸŽ‰ Reward small achievements",
95
+ "๐Ÿงฉ Break tasks into fun-sized chunks",
96
+ "๐Ÿ”„ Replace 'never' with 'sometimes'"
97
+ ]
98
+ else:
99
+ report['type'] = "The Thoughtful Strategist ๐Ÿงญ"
100
+ report['strengths'] = ["Analytical mind", "Detail-oriented"]
101
+ report['tips'] = [
102
+ "๐Ÿ˜„ Schedule daily laughter breaks",
103
+ "๐ŸŒˆ Visualize positive outcomes",
104
+ "๐Ÿ—ฃ๏ธ Practice positive self-talk",
105
+ "๐ŸŽฏ Set micro-goals daily",
106
+ "๐Ÿง˜โ™€๏ธ Try 5-minute mindfulness",
107
+ "๐Ÿ“š Read humorous content",
108
+ "๐Ÿ”„ Reframe 'problems' as 'challenges'",
109
+ "๐ŸŽ Reward progress, not perfection",
110
+ "๐Ÿค Share worries with friends",
111
+ "โœจ Celebrate small wins"
112
+ ]
113
+
114
+ report['quote'] = client.chat.completions.create(
115
+ model="mixtral-8x7b-32768",
116
+ messages=[{"role": "user", "content": f"Generate inspirational quote about {report['type']"}]
117
+ ).choices[0].message.content
118
 
119
+ return report
120
+
121
+ def generate_roast(prompt):
122
  response = client.chat.completions.create(
123
  model="mixtral-8x7b-32768",
124
  messages=[
125
+ {"role": "system", "content": """You are a comedian therapist. Roast bad habits in funny way with emojis.
126
+ Example: "Netflix calling you MVP of couch potatoes? ๐Ÿฅ”๐Ÿ“บ"""},
127
  {"role": "user", "content": prompt}
128
  ],
129
+ temperature=0.95
 
130
  )
131
  return response.choices[0].message.content
132
 
133
+ def create_pdf_report(report):
134
+ buffer = io.BytesIO()
135
+ p = canvas.Canvas(buffer, pagesize=letter)
136
+ p.setFont("Helvetica-Bold", 16)
137
+ p.drawString(100, 750, "๐ŸŒŸ Your Personality Report ๐ŸŒŸ")
138
+
139
+ y_position = 700
140
+ p.setFont("Helvetica", 12)
141
+ for line in [
142
+ f"Personality Type: {report['type']}",
143
+ "",
144
+ "Top Strengths:",
145
+ *[f"- {strength}" for strength in report['strengths']],
146
+ "",
147
+ "Growth Tips:",
148
+ *[f"{i+1}. {tip}" for i, tip in enumerate(report['tips'])],
149
+ "",
150
+ f"Inspirational Quote: {report['quote']}"
151
+ ]:
152
+ p.drawString(100, y_position, line)
153
+ y_position -= 15
154
+
155
+ p.save()
156
+ buffer.seek(0)
157
+ return buffer
158
+
159
+ # Initialize session state
160
+ if 'current_q' not in st.session_state:
161
+ st.session_state.current_q = 0
162
+ if 'responses' not in st.session_state:
163
+ st.session_state.responses = []
164
+ if 'show_report' not in st.session_state:
165
+ st.session_state.show_report = False
166
+
167
+ # Main UI
168
+ st.title("๐Ÿค– Roast Master Pro")
169
+ st.markdown("### The AI That Roasts You Better Than Your Best Friend ๐Ÿ”ฅ")
170
+
171
+ # Progress bar
172
+ progress = st.session_state.current_q / len(QUESTIONS)
173
+ st.markdown(f"""
174
+ <div style="background: #f0f2f6; border-radius: 15px; padding: 5px; margin: 20px 0;">
175
+ <div class="progress-bar" style="width: {progress * 100}%;"></div>
176
+ </div>
177
+ """, unsafe_allow_html=True)
178
+
179
+ # Conversation flow
180
+ if not st.session_state.show_report:
181
+ if st.session_state.current_q < len(QUESTIONS):
182
+ q = QUESTIONS[st.session_state.current_q]
183
+ with st.chat_message("assistant"):
184
+ st.markdown(f"### {q['text']}")
185
+
186
+ if q['type'] == "funny":
187
+ st.markdown('<div class="emoji-float">๐Ÿ˜‚ ๐ŸŽญ ๐Ÿคช</div>', unsafe_allow_html=True)
188
+ else:
189
+ st.markdown('<div class="emoji-float">๐Ÿง  ๐Ÿ’ก ๐Ÿ”</div>', unsafe_allow_html=True)
190
+
191
+ user_input = st.text_input("Your response:", key=f"q{st.session_state.current_q}")
192
+
193
+ if st.button("Next โžก๏ธ"):
194
+ st.session_state.responses.append(user_input)
195
+ st.session_state.current_q += 1
196
+ st.experimental_rerun()
197
+ else:
198
+ st.session_state.show_report = True
199
+ st.experimental_rerun()
200
+ else:
201
+ # Personality analysis
202
+ analysis = analyze_personality(st.session_state.responses)
203
+ report = generate_personality_report(analysis)
204
+
205
+ # Show report
206
+ st.balloons()
207
+ st.success("๐ŸŽ‰ Personality Analysis Complete!")
208
+
209
+ col1, col2 = st.columns(2)
210
+ with col1:
211
  st.markdown(f"""
212
+ ### ๏ฟฝ๏ฟฝ Your Personality Type
213
+ # {report['type']}
214
+ """)
215
+ st.markdown(f"### ๐Ÿ’ฌ Inspirational Quote:")
216
+ st.info(f'"{report["quote"]}"')
217
 
218
+ with col2:
219
+ st.markdown("### ๐Ÿ† Top Strengths")
220
+ for strength in report['strengths']:
221
+ st.markdown(f"- ๐ŸŒŸ {strength}")
222
+
223
+ st.markdown("### ๐Ÿ“ˆ Resilience Score")
224
+ st.metric(label="", value=f"{analysis['resilience']}/100")
225
+
226
+ st.markdown("---")
227
+ st.markdown("### ๐Ÿ› ๏ธ 10 Growth Tips")
228
+ cols = st.columns(2)
229
+ for i, tip in enumerate(report['tips']):
230
+ cols[i%2].markdown(f"{i+1}. {tip}")
231
+
232
+ # PDF Download
233
+ pdf = create_pdf_report(report)
234
+ st.download_button(
235
+ label="๐Ÿ“ฅ Download Full Report",
236
+ data=pdf,
237
+ file_name="personality_report.pdf",
238
+ mime="application/pdf"
239
+ )
240
+
241
+ if st.button("๐Ÿ”„ Start Over"):
242
+ st.session_state.clear()
243
+ st.experimental_rerun()
244
 
245
+ # Sidebar
246
  with st.sidebar:
 
247
  st.markdown("""
248
+ ## ๐ŸŽฎ How to Play
249
+ 1. Answer funny/serious questions
250
+ 2. Get roasted ๐Ÿ”ฅ
251
+ 3. Receive personality analysis
252
+ 4. Get 10 growth tips
253
+ 5. Download/share report!
254
 
255
+ **Features:**
256
+ - ๐Ÿค– AI-powered insights
257
+ - ๐Ÿ˜‚ Humor therapy
258
+ - ๐Ÿ“Š Personality assessment
259
+ - ๐Ÿ“ฅ PDF report download
260
  """)
261
+ st.image("https://i.imgur.com/5X7nKNy.png", width=250)