Spaces:
Sleeping
Sleeping
File size: 4,811 Bytes
c9a6260 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
import streamlit as st
import pickle
import pandas as pd
# Background and styling
st.markdown(
"""
<style>
.stApp::before {
content: "";
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: url("https://images.unsplash.com/photo-1516574187841-cb9cc2ca948b");
background-size: cover;
background-position: center;
background-attachment: fixed;
opacity: 0.15;
z-index: -1;
}
.stApp {
background-color: #1e1e2f;
color: #ffffff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h1, h2, h3, h4, h5 {
color: #ffd700 !important;
}
.block-container {
padding: 2rem;
}
p, li {
text-align: justify;
color: #e0e0e0;
font-size: 16px;
}
.center-button {
display: flex;
justify-content: center;
margin-top: 30px;
}
.stButton>button {
background-color: #ff7f50;
color: white;
border-radius: 12px;
padding: 0.5em 2em;
font-size: 16px;
transition: 0.3s;
}
.stButton>button:hover {
background-color: #ff5722;
font-weight: bold;
}
</style>
""",
unsafe_allow_html=True
)
# Title and Form
st.title("π§ Mental Health Detection")
st.markdown("#### Please fill in your daily activity details to get a mental wellness insight.")
# Input Form
with st.form("mental_health_form"):
col1, col2 = st.columns(2)
with col1:
Age=st.number_input("Age",min_value=10,max_value=100)
work_hours = st.number_input("π Working hours per week", min_value=20, max_value=70)
Family_history = st.selectbox("π¨βπ©βπ§ Family history of mental health issues?", ("Yes", "No"))
sleep = st.number_input("π΄ Sleep hours per day", min_value=4, max_value=10)
Diet = st.selectbox("π½οΈ Diet quality", ("Good", "Average", "Poor"))
with col2:
Gender = st.selectbox("Gender",['Male',"Female","Others"])
stress = st.slider("π° Stress levels (1-10)", min_value=0, max_value=10)
physical_activity = st.number_input("π Physical activity (minutes/day)", min_value=0, max_value=180)
social_interaction = st.slider("π£οΈ Social interaction level (1-10)", min_value=0, max_value=10)
# Center the submit button
st.markdown('<div class="center-button">', unsafe_allow_html=True)
submitted = st.form_submit_button("π Predict")
st.markdown('</div>', unsafe_allow_html=True)
df = pd.DataFrame([[Age,Gender,work_hours, Family_history, sleep, stress,
physical_activity, social_interaction, Diet]],
columns=['Age','Gender','Work Hours', 'Family History', 'Sleep Hours',
'Stress Level', 'Physical Activity',
'Social Interaction', 'Diet Quality'])
# Model prediction
if submitted:
with open("encoding.pkl", 'rb') as file:
encode = pickle.load(file)
with open("model.pkl", "rb") as file:
model = pickle.load(file)
with open("pip.pkl",'rb') as file:
pipe=pickle.load(file)
transformed_df = pipe.transform(df)
prediction = model.predict(transformed_df)[0]
# Output results
if prediction == 1:
st.warning("β οΈ You may be at risk for mental health issues. It's recommended to take some self-care actions.")
else:
st.success("β
You're doing well! Keep up the good habits.")
# Personalized Tips
st.markdown("### π‘ Personalized Tips to Boost Your Mental Health")
tips = []
if Diet != "Good":
tips.append("π **Eat a Nutrient-Rich Snack Daily** \nSupports brain health with omega-3s, vitamins, and minerals.")
if stress > 6:
tips.append("π§ **Meditate or Stretch for 15 Minutes** \nEases anxiety and improves focus.")
tips.append("π¬οΈ **Practice Deep Breathing for 10 Minutes** \nLowers stress and anxiety levels.")
tips.append("π° **Drink Water & Take 5-Minute Breaks** \nHydration supports mental clarity.")
tips.append("π§ **Walk 30 Minutes Daily with Music** \nReduces stress and uplifts mood.")
if sleep < 7:
tips.append("π **Set a Consistent Sleep Schedule (7β8 Hours)** \nImproves energy and stabilizes mood.")
if work_hours > 50:
tips.append("π
**Limit Work to 40β45 Hours Per Week** \nPrevents burnout and enhances productivity.")
if social_interaction < 5:
tips.append("π₯ **Spend at Least 1 Hour Socializing Daily** \nBoosts emotional well-being and reduces isolation.")
for tip in tips:
st.markdown(f"<p>{tip}</p>", unsafe_allow_html=True)
|