Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,8 @@ import os
|
|
| 9 |
st.markdown(
|
| 10 |
"""
|
| 11 |
<style>
|
| 12 |
-
/*
|
| 13 |
-
|
| 14 |
background-color: #222;
|
| 15 |
background-image:
|
| 16 |
linear-gradient(45deg, #000 25%, transparent 25%),
|
|
@@ -19,8 +19,6 @@ st.markdown(
|
|
| 19 |
linear-gradient(-45deg, transparent 75%, #fff 75%);
|
| 20 |
background-size: 56.57px 56.57px;
|
| 21 |
background-position: 0 0, 0 0, 28.28px 28.28px, 28.28px 28.28px;
|
| 22 |
-
color: #fff;
|
| 23 |
-
font-family: 'Roboto', sans-serif;
|
| 24 |
}
|
| 25 |
/* Glassy Containers with Unique Pattern Borders and Hover Effects */
|
| 26 |
.glassy-container {
|
|
@@ -102,14 +100,14 @@ st.markdown(
|
|
| 102 |
)
|
| 103 |
|
| 104 |
# ---------- App Title & Description ----------
|
| 105 |
-
st.title("Mini
|
| 106 |
st.markdown(
|
| 107 |
-
"#### Discover your self-actualizing potential with this Mini
|
| 108 |
"This assessment is designed for college-age and adult individuals to help reveal attitudes "
|
| 109 |
"and values that indicate positive mental health."
|
| 110 |
)
|
| 111 |
|
| 112 |
-
# ---------- Define Sample
|
| 113 |
questions = [
|
| 114 |
{"trait": "Time Competence", "question": "I am focused on and engaged with the present moment."},
|
| 115 |
{"trait": "Inner-Directed", "question": "I trust my inner guidance when making decisions."},
|
|
@@ -178,11 +176,11 @@ with st.form(key="assessment_form"):
|
|
| 178 |
if submitted and name:
|
| 179 |
st.success(f"Thank you, {name}! Your results are ready.")
|
| 180 |
|
| 181 |
-
# Display the
|
| 182 |
st.markdown(
|
| 183 |
f"""
|
| 184 |
<div class="glassy-container">
|
| 185 |
-
<h2>{name}'s
|
| 186 |
<ul>
|
| 187 |
{"".join([f"<li><strong>{trait}:</strong> {score}/5</li>" for trait, score in user_responses.items()])}
|
| 188 |
</ul>
|
|
@@ -210,12 +208,12 @@ if submitted and name:
|
|
| 210 |
).properties(width=700, height=400)
|
| 211 |
st.altair_chart(chart, use_container_width=True)
|
| 212 |
|
| 213 |
-
# Save chart as image for inclusion in PDF (requires
|
| 214 |
chart_path = "chart.png"
|
| 215 |
try:
|
| 216 |
chart.save(chart_path, scale_factor=2.0)
|
| 217 |
except Exception as e:
|
| 218 |
-
st.error("Error saving chart image: " + str(e))
|
| 219 |
chart_path = None
|
| 220 |
|
| 221 |
# ---------- PDF Report Generation Function using FPDF ----------
|
|
@@ -226,14 +224,14 @@ if submitted and name:
|
|
| 226 |
pdf.set_fill_color(0, 0, 0)
|
| 227 |
pdf.set_text_color(255, 255, 255)
|
| 228 |
pdf.set_font("Arial", "B", 20)
|
| 229 |
-
pdf.cell(0, 15, f"{name}'s
|
| 230 |
pdf.set_font("Arial", "", 10)
|
| 231 |
pdf.set_text_color(0, 0, 0)
|
| 232 |
pdf.cell(0, 10, f"Generated on: {generated_on}", ln=True, align="C")
|
| 233 |
pdf.ln(5)
|
| 234 |
-
#
|
| 235 |
pdf.set_font("Arial", "B", 12)
|
| 236 |
-
pdf.cell(0, 10, "
|
| 237 |
pdf.set_font("Arial", "", 12)
|
| 238 |
for trait, score in responses.items():
|
| 239 |
pdf.cell(0, 10, f"{trait}: {score}/5", ln=True)
|
|
@@ -251,7 +249,7 @@ if submitted and name:
|
|
| 251 |
pdf.cell(0, 10, "Score Visualization:", ln=True)
|
| 252 |
pdf.image(chart_path, x=10, y=pdf.get_y(), w=pdf.epw)
|
| 253 |
pdf.ln(5)
|
| 254 |
-
# Footer
|
| 255 |
pdf.set_y(-20)
|
| 256 |
pdf.set_font("Arial", "I", 8)
|
| 257 |
pdf.cell(0, 10, "Developed by Kabura Kuria - Contact: +254 707 865 934", 0, 0, "C")
|
|
|
|
| 9 |
st.markdown(
|
| 10 |
"""
|
| 11 |
<style>
|
| 12 |
+
/* Apply background pattern to the Streamlit app container */
|
| 13 |
+
[data-testid="stAppViewContainer"] {
|
| 14 |
background-color: #222;
|
| 15 |
background-image:
|
| 16 |
linear-gradient(45deg, #000 25%, transparent 25%),
|
|
|
|
| 19 |
linear-gradient(-45deg, transparent 75%, #fff 75%);
|
| 20 |
background-size: 56.57px 56.57px;
|
| 21 |
background-position: 0 0, 0 0, 28.28px 28.28px, 28.28px 28.28px;
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
/* Glassy Containers with Unique Pattern Borders and Hover Effects */
|
| 24 |
.glassy-container {
|
|
|
|
| 100 |
)
|
| 101 |
|
| 102 |
# ---------- App Title & Description ----------
|
| 103 |
+
st.title("Mini Orientation Inventory")
|
| 104 |
st.markdown(
|
| 105 |
+
"#### Discover your self-actualizing potential with this Mini Orientation Inventory. "
|
| 106 |
"This assessment is designed for college-age and adult individuals to help reveal attitudes "
|
| 107 |
"and values that indicate positive mental health."
|
| 108 |
)
|
| 109 |
|
| 110 |
+
# ---------- Define Sample Assessment Questions ----------
|
| 111 |
questions = [
|
| 112 |
{"trait": "Time Competence", "question": "I am focused on and engaged with the present moment."},
|
| 113 |
{"trait": "Inner-Directed", "question": "I trust my inner guidance when making decisions."},
|
|
|
|
| 176 |
if submitted and name:
|
| 177 |
st.success(f"Thank you, {name}! Your results are ready.")
|
| 178 |
|
| 179 |
+
# Display the Orientation Profile in a glassy container
|
| 180 |
st.markdown(
|
| 181 |
f"""
|
| 182 |
<div class="glassy-container">
|
| 183 |
+
<h2>{name}'s Orientation Profile</h2>
|
| 184 |
<ul>
|
| 185 |
{"".join([f"<li><strong>{trait}:</strong> {score}/5</li>" for trait, score in user_responses.items()])}
|
| 186 |
</ul>
|
|
|
|
| 208 |
).properties(width=700, height=400)
|
| 209 |
st.altair_chart(chart, use_container_width=True)
|
| 210 |
|
| 211 |
+
# Save chart as image for inclusion in PDF (requires vl-convert-python)
|
| 212 |
chart_path = "chart.png"
|
| 213 |
try:
|
| 214 |
chart.save(chart_path, scale_factor=2.0)
|
| 215 |
except Exception as e:
|
| 216 |
+
st.error("Error saving chart image: " + str(e) + ". Please install the 'vl-convert-python' package (pip install vl-convert-python) to enable PNG export.")
|
| 217 |
chart_path = None
|
| 218 |
|
| 219 |
# ---------- PDF Report Generation Function using FPDF ----------
|
|
|
|
| 224 |
pdf.set_fill_color(0, 0, 0)
|
| 225 |
pdf.set_text_color(255, 255, 255)
|
| 226 |
pdf.set_font("Arial", "B", 20)
|
| 227 |
+
pdf.cell(0, 15, f"{name}'s Orientation Report", ln=True, align="C", fill=True)
|
| 228 |
pdf.set_font("Arial", "", 10)
|
| 229 |
pdf.set_text_color(0, 0, 0)
|
| 230 |
pdf.cell(0, 10, f"Generated on: {generated_on}", ln=True, align="C")
|
| 231 |
pdf.ln(5)
|
| 232 |
+
# Orientation Profile
|
| 233 |
pdf.set_font("Arial", "B", 12)
|
| 234 |
+
pdf.cell(0, 10, "Orientation Profile:", ln=True)
|
| 235 |
pdf.set_font("Arial", "", 12)
|
| 236 |
for trait, score in responses.items():
|
| 237 |
pdf.cell(0, 10, f"{trait}: {score}/5", ln=True)
|
|
|
|
| 249 |
pdf.cell(0, 10, "Score Visualization:", ln=True)
|
| 250 |
pdf.image(chart_path, x=10, y=pdf.get_y(), w=pdf.epw)
|
| 251 |
pdf.ln(5)
|
| 252 |
+
# Footer
|
| 253 |
pdf.set_y(-20)
|
| 254 |
pdf.set_font("Arial", "I", 8)
|
| 255 |
pdf.cell(0, 10, "Developed by Kabura Kuria - Contact: +254 707 865 934", 0, 0, "C")
|