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