sunbal7 commited on
Commit
cba680e
Β·
verified Β·
1 Parent(s): a16df81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -59
app.py CHANGED
@@ -12,7 +12,7 @@ import io
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("""
@@ -63,10 +63,11 @@ def analyze_personality(responses):
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)
@@ -74,59 +75,66 @@ def analyze_personality(responses):
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
- def generate_roast(prompt):
120
- response = client.chat.completions.create(
121
- model="mixtral-8x7b-32768",
122
- messages=[
123
- {"role": "system", "content": """You are a comedian therapist. Roast bad habits in funny way with emojis.
124
- Example: "Netflix calling you MVP of couch potatoes? πŸ₯”πŸ“Ί"""},
125
- {"role": "user", "content": prompt}
126
- ],
127
- temperature=0.95
128
- )
129
- return response.choices[0].message.content
130
 
131
  def create_pdf_report(report):
132
  buffer = io.BytesIO()
@@ -191,10 +199,10 @@ if not st.session_state.show_report:
191
  if st.button("Next ➑️"):
192
  st.session_state.responses.append(user_input)
193
  st.session_state.current_q += 1
194
- st.experimental_rerun()
195
  else:
196
  st.session_state.show_report = True
197
- st.experimental_rerun()
198
  else:
199
  # Personality analysis
200
  analysis = analyze_personality(st.session_state.responses)
@@ -238,7 +246,7 @@ else:
238
 
239
  if st.button("πŸ”„ Start Over"):
240
  st.session_state.clear()
241
- st.experimental_rerun()
242
 
243
  # Sidebar
244
  with st.sidebar:
@@ -256,4 +264,3 @@ with st.sidebar:
256
  - πŸ“Š Personality assessment
257
  - πŸ“₯ PDF report download
258
  """)
259
- st.image("https://i.imgur.com/5X7nKNy.png", width=250)
 
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="center", page_icon="πŸ€–")
16
 
17
  # Custom CSS
18
  st.markdown("""
 
63
  }
64
 
65
  for response in responses:
66
+ if response: # Handle empty responses
67
+ blob = TextBlob(response)
68
+ analysis['humor_score'] += len(re.findall(r'πŸ˜‚|🀣|😜', response)) * 5
69
+ analysis['negativity'] += blob.sentiment.polarity
70
+ analysis['absolutes'] += len(re.findall(r'\b(always|never|everyone|nobody)\b', response, re.I))
71
 
72
  analysis['resilience'] -= analysis['absolutes'] * 3
73
  analysis['resilience'] = max(min(analysis['resilience'], 100), 0)
 
75
 
76
  def generate_personality_report(analysis):
77
  report = {
78
+ 'type': "The Balanced Visionary πŸ¦‰",
79
+ 'strengths': ["Adaptability", "Critical thinking"],
80
+ 'tips': [
81
+ "🎯 Practice mindful decision-making",
82
+ "πŸ§˜β™‚οΈ Balance work and relaxation",
83
+ "πŸ“š Learn something new daily",
84
+ "🀝 Cultivate meaningful relationships",
85
+ "🌱 Embrace gradual improvement",
86
+ "πŸŽ‰ Celebrate small victories",
87
+ "🧠 Challenge cognitive distortions",
88
+ "πŸ’‘ Reframe negative thoughts",
89
+ "πŸ”„ Embrace flexible thinking",
90
+ "🌟 Believe in growth potential"
91
+ ],
92
+ 'quote': "The only limit to your growth is your imagination!"
93
  }
94
 
95
+ try:
96
+ if analysis['humor_score'] > 15:
97
+ report['type'] = "The Resilient Jester πŸƒ"
98
+ report['strengths'] = ["Stress diffuser", "Creative thinker"]
99
+ report['tips'] = [
100
+ "🎯 Use humor to reframe challenges",
101
+ "πŸ§˜β™‚οΈ Balance jokes with mindfulness",
102
+ "πŸ“… Schedule 'serious time' daily",
103
+ "🎭 Channel creativity productively",
104
+ "πŸ€” Challenge 'all-or-nothing' thoughts",
105
+ "πŸ“ Journal funny observations",
106
+ "πŸŒ… Start day with positive affirmation",
107
+ "πŸŽ‰ Reward small achievements",
108
+ "🧩 Break tasks into fun-sized chunks",
109
+ "πŸ”„ Replace 'never' with 'sometimes'"
110
+ ]
111
+ else:
112
+ report['type'] = "The Thoughtful Strategist 🧭"
113
+ report['strengths'] = ["Analytical mind", "Detail-oriented"]
114
+ report['tips'] = [
115
+ "πŸ˜„ Schedule daily laughter breaks",
116
+ "🌈 Visualize positive outcomes",
117
+ "πŸ—£οΈ Practice positive self-talk",
118
+ "🎯 Set micro-goals daily",
119
+ "πŸ§˜β™€οΈ Try 5-minute mindfulness",
120
+ "πŸ“š Read humorous content",
121
+ "πŸ”„ Reframe 'problems' as 'challenges'",
122
+ "🎁 Reward progress, not perfection",
123
+ "🀝 Share worries with friends",
124
+ "✨ Celebrate small wins"
125
+ ]
 
 
 
 
126
 
127
+ # Generate inspirational quote
128
+ quote_response = client.chat.completions.create(
129
+ model="mixtral-8x7b-32768",
130
+ messages=[{"role": "user", "content": f"Generate inspirational quote about {report['type']}"}]
131
+ )
132
+ report['quote'] = quote_response.choices[0].message.content
133
+
134
+ except Exception as e:
135
+ st.error(f"Error generating report: {str(e)}")
136
+
137
+ return report
138
 
139
  def create_pdf_report(report):
140
  buffer = io.BytesIO()
 
199
  if st.button("Next ➑️"):
200
  st.session_state.responses.append(user_input)
201
  st.session_state.current_q += 1
202
+ st.rerun()
203
  else:
204
  st.session_state.show_report = True
205
+ st.rerun()
206
  else:
207
  # Personality analysis
208
  analysis = analyze_personality(st.session_state.responses)
 
246
 
247
  if st.button("πŸ”„ Start Over"):
248
  st.session_state.clear()
249
+ st.rerun()
250
 
251
  # Sidebar
252
  with st.sidebar:
 
264
  - πŸ“Š Personality assessment
265
  - πŸ“₯ PDF report download
266
  """)