Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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="
|
| 16 |
|
| 17 |
# Custom CSS
|
| 18 |
st.markdown("""
|
|
@@ -63,10 +63,11 @@ def analyze_personality(responses):
|
|
| 63 |
}
|
| 64 |
|
| 65 |
for response in responses:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 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 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
return
|
| 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.
|
| 195 |
else:
|
| 196 |
st.session_state.show_report = True
|
| 197 |
-
st.
|
| 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.
|
| 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 |
""")
|
|
|