Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ except Exception as e:
|
|
20 |
st.stop()
|
21 |
|
22 |
# Configure Streamlit
|
23 |
-
st.set_page_config(page_title="
|
24 |
|
25 |
# Custom CSS
|
26 |
st.markdown("""
|
@@ -40,12 +40,19 @@ st.markdown("""
|
|
40 |
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
41 |
}
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
.social-post {
|
44 |
background: #e3f2fd;
|
45 |
padding: 20px;
|
46 |
border-radius: 15px;
|
47 |
margin: 15px 0;
|
48 |
-
border: 2px solid #2196F3;
|
49 |
}
|
50 |
|
51 |
.nav-btn {
|
@@ -56,6 +63,7 @@ st.markdown("""
|
|
56 |
|
57 |
.nav-btn:hover {
|
58 |
transform: scale(1.02);
|
|
|
59 |
}
|
60 |
</style>
|
61 |
""", unsafe_allow_html=True)
|
@@ -63,11 +71,16 @@ st.markdown("""
|
|
63 |
# Personality configuration
|
64 |
OCEAN_TRAITS = ["agreeableness", "openness", "conscientiousness", "extraversion", "neuroticism"]
|
65 |
QUESTION_BANK = [
|
66 |
-
{"text": "If your personality was a pizza topping, what would
|
67 |
-
{"text": "Describe your ideal
|
68 |
-
{"text": "How would you survive a
|
69 |
-
{"text": "What's your spirit animal
|
70 |
-
{"text": "Plan a perfect day
|
|
|
|
|
|
|
|
|
|
|
71 |
]
|
72 |
|
73 |
# Session state management
|
@@ -78,11 +91,11 @@ if 'current_q' not in st.session_state:
|
|
78 |
if 'responses' not in st.session_state:
|
79 |
st.session_state.responses = []
|
80 |
if 'page' not in st.session_state:
|
81 |
-
st.session_state.page = "
|
82 |
|
83 |
-
#
|
84 |
-
def
|
85 |
-
"
|
86 |
response = groq_client.chat.completions.create(
|
87 |
model="mixtral-8x7b-32768",
|
88 |
messages=[{"role": "user", "content": prompt}],
|
@@ -91,15 +104,13 @@ def generate_content(prompt):
|
|
91 |
return response.choices[0].message.content
|
92 |
|
93 |
def analyze_personality(text):
|
94 |
-
"""Personality analysis using KevSun model"""
|
95 |
encoded_input = tokenizer(text, return_tensors='pt', padding=True, truncation=True, max_length=64)
|
96 |
with torch.no_grad():
|
97 |
outputs = model(**encoded_input)
|
98 |
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
99 |
return {trait: score.item() for trait, score in zip(OCEAN_TRAITS, predictions[0])}
|
100 |
|
101 |
-
def create_pdf_report(traits):
|
102 |
-
"""Generate PDF report"""
|
103 |
buffer = io.BytesIO()
|
104 |
p = canvas.Canvas(buffer, pagesize=letter)
|
105 |
p.setFont("Helvetica-Bold", 16)
|
@@ -111,222 +122,43 @@ def create_pdf_report(traits):
|
|
111 |
p.drawString(100, y_position, f"{trait.upper()}: {score:.2f}")
|
112 |
y_position -= 20
|
113 |
|
|
|
|
|
114 |
p.save()
|
115 |
buffer.seek(0)
|
116 |
return buffer
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
-
if st.button("π Start Personality Analysis!", use_container_width=True):
|
128 |
-
st.session_state.started = True
|
129 |
-
st.session_state.selected_questions = random.sample(QUESTION_BANK, 5)
|
130 |
-
st.rerun()
|
131 |
-
else:
|
132 |
-
# Sidebar navigation
|
133 |
-
with st.sidebar:
|
134 |
-
st.title("π§ Navigation")
|
135 |
-
st.markdown("---")
|
136 |
-
nav_options = {
|
137 |
-
"π Report": "View personality breakdown",
|
138 |
-
"π± Social Post": "Generate social media content",
|
139 |
-
"π₯ Download": "Get full PDF report"
|
140 |
-
}
|
141 |
-
|
142 |
-
for option, help_text in nav_options.items():
|
143 |
-
if st.button(option, key=option, use_container_width=True, help=help_text):
|
144 |
-
st.session_state.page = option
|
145 |
-
|
146 |
-
# Question flow
|
147 |
-
if st.session_state.current_q < 5:
|
148 |
-
q = st.session_state.selected_questions[st.session_state.current_q]
|
149 |
-
st.progress(st.session_state.current_q/5, text="Analysis Progress")
|
150 |
-
|
151 |
-
with st.chat_message("assistant"):
|
152 |
-
st.markdown(f"### {q['text']}")
|
153 |
-
user_input = st.text_input("Your response:", key=f"q{st.session_state.current_q}")
|
154 |
-
|
155 |
-
if st.button("Next β‘οΈ"):
|
156 |
-
st.session_state.responses.append(user_input)
|
157 |
-
st.session_state.current_q += 1
|
158 |
-
st.rerun()
|
159 |
-
else:
|
160 |
-
# Process responses
|
161 |
-
traits = analyze_personality("\n".join(st.session_state.responses))
|
162 |
-
|
163 |
-
# Page rendering
|
164 |
-
if st.session_state.page == "π Report":
|
165 |
-
st.header("π Personality Breakdown")
|
166 |
-
cols = st.columns(5)
|
167 |
-
for i, (trait, score) in enumerate(traits.items()):
|
168 |
-
cols[i].metric(label=trait.upper(), value=f"{score:.2f}")
|
169 |
-
|
170 |
-
st.divider()
|
171 |
-
st.header("π‘ Key Insights")
|
172 |
-
insights = generate_content(f"Generate 3 concise personality insights based on these scores: {traits}")
|
173 |
-
st.markdown(f"<div class='social-post'>{insights}</div>", unsafe_allow_html=True)
|
174 |
-
|
175 |
-
elif st.session_state.page == "π± Social Post":
|
176 |
-
st.header("π― Create Social Content")
|
177 |
-
col1, col2 = st.columns(2)
|
178 |
-
with col1:
|
179 |
-
platform = st.selectbox("Select Platform:", ["LinkedIn", "Instagram", "Facebook", "WhatsApp", "Twitter"])
|
180 |
-
with col2:
|
181 |
-
post_style = st.radio("Post Style:", ["π Funny", "πΌ Professional"])
|
182 |
-
|
183 |
-
if st.button("β¨ Generate Post"):
|
184 |
-
style_prompt = "Include humor and memes" if "Funny" in post_style else "Keep professional and inspirational"
|
185 |
-
prompt = f"""Create a {platform} post about personal growth with these traits: {traits}
|
186 |
-
- Style: {style_prompt}
|
187 |
-
- Include relevant emojis
|
188 |
-
- Max 280 characters
|
189 |
-
- Add platform-appropriate hashtags"""
|
190 |
-
|
191 |
-
post = generate_content(prompt)
|
192 |
-
st.session_state.post = post
|
193 |
-
|
194 |
-
if 'post' in st.session_state:
|
195 |
-
st.markdown(f"<div class='social-post'>{st.session_state.post}</div>", unsafe_allow_html=True)
|
196 |
-
st.button("π Copy Content", on_click=lambda: st.write(st.session_state.post))
|
197 |
-
|
198 |
-
elif st.session_state.page == "π₯ Download":
|
199 |
-
st.header("π Complete Report")
|
200 |
-
pdf_buffer = create_pdf_report(traits)
|
201 |
-
st.download_button(
|
202 |
-
"β¬οΈ Download PDF Report",
|
203 |
-
data=pdf_buffer,
|
204 |
-
file_name="persona_report.pdf",
|
205 |
-
mime="application/pdf",
|
206 |
-
use_container_width=True
|
207 |
-
)# app.py
|
208 |
-
import streamlit as st
|
209 |
-
import torch
|
210 |
-
import random
|
211 |
-
import pandas as pd
|
212 |
-
from datetime import datetime
|
213 |
-
from reportlab.lib.pagesizes import letter
|
214 |
-
from reportlab.pdfgen import canvas
|
215 |
-
import io
|
216 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
217 |
-
from groq import Groq
|
218 |
-
|
219 |
-
# Initialize components
|
220 |
-
try:
|
221 |
-
groq_client = Groq(api_key=st.secrets["GROQ_API_KEY"])
|
222 |
-
model = AutoModelForSequenceClassification.from_pretrained("KevSun/Personality_LM", ignore_mismatched_sizes=True)
|
223 |
-
tokenizer = AutoTokenizer.from_pretrained("KevSun/Personality_LM")
|
224 |
-
except Exception as e:
|
225 |
-
st.error(f"Initialization error: {str(e)}")
|
226 |
-
st.stop()
|
227 |
-
|
228 |
-
# Configure Streamlit
|
229 |
-
st.set_page_config(page_title="π PersonaCraft Pro", layout="wide", page_icon="π")
|
230 |
-
|
231 |
-
# Custom CSS
|
232 |
-
st.markdown("""
|
233 |
-
<style>
|
234 |
-
@keyframes fadeIn {
|
235 |
-
from { opacity: 0; }
|
236 |
-
to { opacity: 1; }
|
237 |
-
}
|
238 |
-
|
239 |
-
.quote-box {
|
240 |
-
animation: fadeIn 1s ease-in;
|
241 |
-
border-left: 5px solid #4CAF50;
|
242 |
-
padding: 20px;
|
243 |
-
margin: 20px 0;
|
244 |
-
background: #f8fff9;
|
245 |
-
border-radius: 10px;
|
246 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
247 |
-
}
|
248 |
-
|
249 |
-
.social-post {
|
250 |
-
background: #e3f2fd;
|
251 |
-
padding: 20px;
|
252 |
-
border-radius: 15px;
|
253 |
-
margin: 15px 0;
|
254 |
-
border: 2px solid #2196F3;
|
255 |
-
}
|
256 |
-
|
257 |
-
.nav-btn {
|
258 |
-
margin: 8px 0;
|
259 |
-
width: 100%;
|
260 |
-
transition: all 0.3s ease;
|
261 |
-
}
|
262 |
-
|
263 |
-
.nav-btn:hover {
|
264 |
-
transform: scale(1.02);
|
265 |
-
}
|
266 |
-
</style>
|
267 |
-
""", unsafe_allow_html=True)
|
268 |
-
|
269 |
-
# Personality configuration
|
270 |
-
OCEAN_TRAITS = ["agreeableness", "openness", "conscientiousness", "extraversion", "neuroticism"]
|
271 |
-
QUESTION_BANK = [
|
272 |
-
{"text": "If your personality was a pizza topping, what would it be? π", "trait": "openness"},
|
273 |
-
{"text": "Describe your ideal alarm clock vs reality β°", "trait": "conscientiousness"},
|
274 |
-
{"text": "How would you survive a surprise party? π", "trait": "neuroticism"},
|
275 |
-
{"text": "What's your spirit animal during deadlines? πΎ", "trait": "agreeableness"},
|
276 |
-
{"text": "Plan a perfect day... for your nemesis! π", "trait": "extraversion"}
|
277 |
-
]
|
278 |
-
|
279 |
-
# Session state management
|
280 |
-
if 'started' not in st.session_state:
|
281 |
-
st.session_state.started = False
|
282 |
-
if 'current_q' not in st.session_state:
|
283 |
-
st.session_state.current_q = 0
|
284 |
-
if 'responses' not in st.session_state:
|
285 |
-
st.session_state.responses = []
|
286 |
-
if 'page' not in st.session_state:
|
287 |
-
st.session_state.page = "π Report"
|
288 |
-
|
289 |
-
# Core functions
|
290 |
-
def generate_content(prompt):
|
291 |
-
"""Unified content generation using Groq"""
|
292 |
response = groq_client.chat.completions.create(
|
293 |
model="mixtral-8x7b-32768",
|
294 |
messages=[{"role": "user", "content": prompt}],
|
295 |
-
temperature=0.
|
296 |
)
|
297 |
return response.choices[0].message.content
|
298 |
|
299 |
-
def analyze_personality(text):
|
300 |
-
"""Personality analysis using KevSun model"""
|
301 |
-
encoded_input = tokenizer(text, return_tensors='pt', padding=True, truncation=True, max_length=64)
|
302 |
-
with torch.no_grad():
|
303 |
-
outputs = model(**encoded_input)
|
304 |
-
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
305 |
-
return {trait: score.item() for trait, score in zip(OCEAN_TRAITS, predictions[0])}
|
306 |
-
|
307 |
-
def create_pdf_report(traits):
|
308 |
-
"""Generate PDF report"""
|
309 |
-
buffer = io.BytesIO()
|
310 |
-
p = canvas.Canvas(buffer, pagesize=letter)
|
311 |
-
p.setFont("Helvetica-Bold", 16)
|
312 |
-
p.drawString(100, 750, "π PersonaCraft Pro Report π")
|
313 |
-
p.setFont("Helvetica", 12)
|
314 |
-
|
315 |
-
y_position = 700
|
316 |
-
for trait, score in traits.items():
|
317 |
-
p.drawString(100, y_position, f"{trait.upper()}: {score:.2f}")
|
318 |
-
y_position -= 20
|
319 |
-
|
320 |
-
p.save()
|
321 |
-
buffer.seek(0)
|
322 |
-
return buffer
|
323 |
-
|
324 |
# Main UI
|
325 |
if not st.session_state.started:
|
326 |
st.markdown(f"""
|
327 |
<div class="quote-box">
|
328 |
<h2>π Welcome to PersonaCraft Pro! π</h2>
|
329 |
-
<h3>{
|
330 |
</div>
|
331 |
""", unsafe_allow_html=True)
|
332 |
|
@@ -340,9 +172,10 @@ else:
|
|
340 |
st.title("π§ Navigation")
|
341 |
st.markdown("---")
|
342 |
nav_options = {
|
343 |
-
"π Report": "View personality
|
344 |
-
"π± Social Post": "Generate
|
345 |
-
"
|
|
|
346 |
}
|
347 |
|
348 |
for option, help_text in nav_options.items():
|
@@ -352,7 +185,7 @@ else:
|
|
352 |
# Question flow
|
353 |
if st.session_state.current_q < 5:
|
354 |
q = st.session_state.selected_questions[st.session_state.current_q]
|
355 |
-
st.progress(st.session_state.current_q/5, text="
|
356 |
|
357 |
with st.chat_message("assistant"):
|
358 |
st.markdown(f"### {q['text']}")
|
@@ -365,49 +198,67 @@ else:
|
|
365 |
else:
|
366 |
# Process responses
|
367 |
traits = analyze_personality("\n".join(st.session_state.responses))
|
|
|
368 |
|
369 |
-
#
|
370 |
-
if st.session_state.page == "π Report":
|
371 |
st.header("π Personality Breakdown")
|
372 |
cols = st.columns(5)
|
373 |
for i, (trait, score) in enumerate(traits.items()):
|
374 |
cols[i].metric(label=trait.upper(), value=f"{score:.2f}")
|
375 |
|
376 |
st.divider()
|
377 |
-
st.header("
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
st.
|
|
|
|
|
|
|
383 |
col1, col2 = st.columns(2)
|
384 |
with col1:
|
385 |
platform = st.selectbox("Select Platform:", ["LinkedIn", "Instagram", "Facebook", "WhatsApp", "Twitter"])
|
386 |
with col2:
|
387 |
-
|
388 |
|
389 |
-
if st.button("β¨ Generate Post"):
|
390 |
-
|
391 |
-
prompt = f"""Create a {platform} post about personal growth with these traits: {traits}
|
392 |
-
- Style: {style_prompt}
|
393 |
-
- Include relevant emojis
|
394 |
-
- Max 280 characters
|
395 |
-
- Add platform-appropriate hashtags"""
|
396 |
-
|
397 |
-
post = generate_content(prompt)
|
398 |
st.session_state.post = post
|
399 |
|
400 |
if 'post' in st.session_state:
|
401 |
-
st.markdown(f"
|
402 |
-
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
st.header("π Complete Report")
|
406 |
-
pdf_buffer = create_pdf_report(traits)
|
407 |
st.download_button(
|
408 |
"β¬οΈ Download PDF Report",
|
409 |
data=pdf_buffer,
|
410 |
-
file_name="
|
411 |
mime="application/pdf",
|
412 |
use_container_width=True
|
413 |
)
|
|
|
20 |
st.stop()
|
21 |
|
22 |
# Configure Streamlit
|
23 |
+
st.set_page_config(page_title="π§ PersonaCraft Pro", layout="wide", page_icon="π")
|
24 |
|
25 |
# Custom CSS
|
26 |
st.markdown("""
|
|
|
40 |
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
41 |
}
|
42 |
|
43 |
+
.tip-card {
|
44 |
+
padding: 15px;
|
45 |
+
margin: 10px 0;
|
46 |
+
background: #fff3e0;
|
47 |
+
border-radius: 10px;
|
48 |
+
border: 1px solid #ffab40;
|
49 |
+
}
|
50 |
+
|
51 |
.social-post {
|
52 |
background: #e3f2fd;
|
53 |
padding: 20px;
|
54 |
border-radius: 15px;
|
55 |
margin: 15px 0;
|
|
|
56 |
}
|
57 |
|
58 |
.nav-btn {
|
|
|
63 |
|
64 |
.nav-btn:hover {
|
65 |
transform: scale(1.02);
|
66 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
67 |
}
|
68 |
</style>
|
69 |
""", unsafe_allow_html=True)
|
|
|
71 |
# Personality configuration
|
72 |
OCEAN_TRAITS = ["agreeableness", "openness", "conscientiousness", "extraversion", "neuroticism"]
|
73 |
QUESTION_BANK = [
|
74 |
+
{"text": "If your personality was a pizza topping, what would you be? π", "trait": "openness"},
|
75 |
+
{"text": "Describe your ideal morning vs reality βοΈ", "trait": "conscientiousness"},
|
76 |
+
{"text": "How would you survive a zombie apocalypse? π§", "trait": "neuroticism"},
|
77 |
+
{"text": "What's your spirit animal in meetings? π¦", "trait": "agreeableness"},
|
78 |
+
{"text": "Plan a perfect day for your arch-rival π", "trait": "extraversion"},
|
79 |
+
{"text": "If stress was weather, what's your forecast? βοΈ", "trait": "neuroticism"},
|
80 |
+
{"text": "What would your Netflix history say about you? π¬", "trait": "openness"},
|
81 |
+
{"text": "Describe your phone as a Shakespearean sonnet π±", "trait": "conscientiousness"},
|
82 |
+
{"text": "React to 'We need to talk' π¬", "trait": "agreeableness"},
|
83 |
+
{"text": "Your superhero name in awkward situations? π¦Έ", "trait": "extraversion"}
|
84 |
]
|
85 |
|
86 |
# Session state management
|
|
|
91 |
if 'responses' not in st.session_state:
|
92 |
st.session_state.responses = []
|
93 |
if 'page' not in st.session_state:
|
94 |
+
st.session_state.page = "π Home"
|
95 |
|
96 |
+
# Functions
|
97 |
+
def generate_quote():
|
98 |
+
prompt = "Create an inspirational quote about self-improvement with 2 emojis"
|
99 |
response = groq_client.chat.completions.create(
|
100 |
model="mixtral-8x7b-32768",
|
101 |
messages=[{"role": "user", "content": prompt}],
|
|
|
104 |
return response.choices[0].message.content
|
105 |
|
106 |
def analyze_personality(text):
|
|
|
107 |
encoded_input = tokenizer(text, return_tensors='pt', padding=True, truncation=True, max_length=64)
|
108 |
with torch.no_grad():
|
109 |
outputs = model(**encoded_input)
|
110 |
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
111 |
return {trait: score.item() for trait, score in zip(OCEAN_TRAITS, predictions[0])}
|
112 |
|
113 |
+
def create_pdf_report(traits, quote):
|
|
|
114 |
buffer = io.BytesIO()
|
115 |
p = canvas.Canvas(buffer, pagesize=letter)
|
116 |
p.setFont("Helvetica-Bold", 16)
|
|
|
122 |
p.drawString(100, y_position, f"{trait.upper()}: {score:.2f}")
|
123 |
y_position -= 20
|
124 |
|
125 |
+
p.drawString(100, y_position-40, "Personalized Quote:")
|
126 |
+
p.drawString(100, y_position-60, quote)
|
127 |
p.save()
|
128 |
buffer.seek(0)
|
129 |
return buffer
|
130 |
|
131 |
+
def generate_social_post(platform, tone, traits):
|
132 |
+
tone_instructions = {
|
133 |
+
"funny": "Include humor and 3+ emojis. Make it lighthearted but not offensive",
|
134 |
+
"serious": "Professional tone with inspirational message. Use 1-2 relevant emojis"
|
135 |
+
}
|
136 |
+
platform_formats = {
|
137 |
+
"LinkedIn": "professional networking style",
|
138 |
+
"Instagram": "visual storytelling with emojis",
|
139 |
+
"Facebook": "community-oriented friendly tone",
|
140 |
+
"WhatsApp": "casual conversational style",
|
141 |
+
"Twitter": "concise with trending hashtags"
|
142 |
+
}
|
143 |
+
prompt = f"""Create a {tone} {platform} post about personal growth using these traits:
|
144 |
+
{traits}
|
145 |
+
Format: {platform_formats[platform]}
|
146 |
+
Tone: {tone_instructions[tone]}
|
147 |
+
Max length: 280 characters"""
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
response = groq_client.chat.completions.create(
|
150 |
model="mixtral-8x7b-32768",
|
151 |
messages=[{"role": "user", "content": prompt}],
|
152 |
+
temperature=0.9 if tone == "funny" else 0.5
|
153 |
)
|
154 |
return response.choices[0].message.content
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
# Main UI
|
157 |
if not st.session_state.started:
|
158 |
st.markdown(f"""
|
159 |
<div class="quote-box">
|
160 |
<h2>π Welcome to PersonaCraft Pro! π</h2>
|
161 |
+
<h3>{generate_quote()}</h3>
|
162 |
</div>
|
163 |
""", unsafe_allow_html=True)
|
164 |
|
|
|
172 |
st.title("π§ Navigation")
|
173 |
st.markdown("---")
|
174 |
nav_options = {
|
175 |
+
"π Personality Report": "View detailed personality analysis",
|
176 |
+
"π± Social Media Post": "Generate platform-specific posts",
|
177 |
+
"π‘ Success Tips": "Get personalized improvement tips",
|
178 |
+
"π₯ Download Report": "Download complete PDF report"
|
179 |
}
|
180 |
|
181 |
for option, help_text in nav_options.items():
|
|
|
185 |
# Question flow
|
186 |
if st.session_state.current_q < 5:
|
187 |
q = st.session_state.selected_questions[st.session_state.current_q]
|
188 |
+
st.progress(st.session_state.current_q/5, text="Assessment Progress")
|
189 |
|
190 |
with st.chat_message("assistant"):
|
191 |
st.markdown(f"### {q['text']}")
|
|
|
198 |
else:
|
199 |
# Process responses
|
200 |
traits = analyze_personality("\n".join(st.session_state.responses))
|
201 |
+
quote = generate_quote()
|
202 |
|
203 |
+
# Current page display
|
204 |
+
if st.session_state.page == "π Personality Report":
|
205 |
st.header("π Personality Breakdown")
|
206 |
cols = st.columns(5)
|
207 |
for i, (trait, score) in enumerate(traits.items()):
|
208 |
cols[i].metric(label=trait.upper(), value=f"{score:.2f}")
|
209 |
|
210 |
st.divider()
|
211 |
+
st.header("π Emotional Landscape")
|
212 |
+
df = pd.DataFrame({
|
213 |
+
"Trait": traits.keys(),
|
214 |
+
"Score": traits.values()
|
215 |
+
})
|
216 |
+
st.bar_chart(df.set_index("Trait"))
|
217 |
+
|
218 |
+
elif st.session_state.page == "π± Social Media Post":
|
219 |
+
st.header("π¨ Create Social Post")
|
220 |
col1, col2 = st.columns(2)
|
221 |
with col1:
|
222 |
platform = st.selectbox("Select Platform:", ["LinkedIn", "Instagram", "Facebook", "WhatsApp", "Twitter"])
|
223 |
with col2:
|
224 |
+
tone = st.radio("Post Tone:", ["π Funny", "π― Serious"], horizontal=True)
|
225 |
|
226 |
+
if st.button("β¨ Generate Post", type="primary"):
|
227 |
+
post = generate_social_post(platform, tone.split()[1].lower(), traits)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
st.session_state.post = post
|
229 |
|
230 |
if 'post' in st.session_state:
|
231 |
+
st.markdown(f"""
|
232 |
+
<div class="social-post">
|
233 |
+
<p>{st.session_state.post}</p>
|
234 |
+
</div>
|
235 |
+
""", unsafe_allow_html=True)
|
236 |
+
st.button("π Copy Post", on_click=lambda: st.write(st.session_state.post))
|
237 |
+
|
238 |
+
elif st.session_state.page == "π‘ Success Tips":
|
239 |
+
st.header("π Personality Success Tips")
|
240 |
+
tips = [
|
241 |
+
"π
Morning reflection: Start each day with 5 minutes of self-reflection",
|
242 |
+
"π€ Weekly connection: Have one meaningful conversation with someone new",
|
243 |
+
"π― SMART goals: Set weekly Specific-Measurable-Achievable-Relevant-Timebound goals",
|
244 |
+
"π§ Neuroplasticity practice: Learn one new skill each month",
|
245 |
+
"π Cross-training: Read outside your field 30 minutes daily",
|
246 |
+
"π¬ Active listening: Practice repeating back what others say before responding",
|
247 |
+
"π Feedback loop: Request constructive feedback weekly",
|
248 |
+
"βοΈ Balance audit: Weekly review of work-life harmony",
|
249 |
+
"π Emotional agility: Label emotions precisely throughout the day",
|
250 |
+
"π Growth challenges: Monthly comfort-zone expansion activity"
|
251 |
+
]
|
252 |
+
for tip in tips:
|
253 |
+
st.markdown(f"<div class='tip-card'>{tip}</div>", unsafe_allow_html=True)
|
254 |
+
|
255 |
+
elif st.session_state.page == "π₯ Download Report":
|
256 |
st.header("π Complete Report")
|
257 |
+
pdf_buffer = create_pdf_report(traits, quote)
|
258 |
st.download_button(
|
259 |
"β¬οΈ Download PDF Report",
|
260 |
data=pdf_buffer,
|
261 |
+
file_name="personacraft_pro_report.pdf",
|
262 |
mime="application/pdf",
|
263 |
use_container_width=True
|
264 |
)
|