Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
13 |
|
14 |
-
# Custom CSS
|
15 |
st.markdown("""
|
16 |
<style>
|
17 |
-
@keyframes
|
18 |
-
0% { transform:
|
19 |
-
50% { transform:
|
20 |
-
100% { transform:
|
21 |
}
|
22 |
|
23 |
-
.
|
24 |
-
animation:
|
25 |
-
font-size:
|
26 |
text-align: center;
|
27 |
}
|
28 |
|
29 |
.progress-bar {
|
30 |
-
height:
|
31 |
-
border-radius:
|
32 |
-
background: #
|
33 |
-
transition: width 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
</style>
|
36 |
""", unsafe_allow_html=True)
|
37 |
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
analysis = {
|
41 |
-
'
|
42 |
-
'
|
43 |
-
'
|
|
|
44 |
}
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
|
|
|
|
|
50 |
return analysis
|
51 |
|
52 |
-
def
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
|
|
|
|
|
|
58 |
response = client.chat.completions.create(
|
59 |
model="mixtral-8x7b-32768",
|
60 |
messages=[
|
61 |
-
{"role": "system", "content":
|
|
|
62 |
{"role": "user", "content": prompt}
|
63 |
],
|
64 |
-
temperature=0.
|
65 |
-
max_tokens=100
|
66 |
)
|
67 |
return response.choices[0].message.content
|
68 |
|
69 |
-
def
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
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 |
st.markdown(f"""
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
"""
|
111 |
|
112 |
-
|
113 |
-
st.
|
114 |
-
for
|
115 |
-
st.markdown(f"- {
|
116 |
-
|
117 |
-
|
118 |
-
st.
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
# Sidebar
|
122 |
with st.sidebar:
|
123 |
-
st.header("How It Works")
|
124 |
st.markdown("""
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
|
130 |
-
**
|
131 |
-
-
|
132 |
-
- Humor
|
133 |
-
-
|
|
|
134 |
""")
|
135 |
-
st.image("https://i.imgur.com/
|
|
|
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)
|