Surendradjh commited on
Commit
c9a6260
Β·
verified Β·
1 Parent(s): bf95364

Update deply.py

Browse files
Files changed (1) hide show
  1. deply.py +143 -141
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
- work_hours = st.number_input("πŸ•’ Working hours per week", min_value=20, max_value=70)
79
- Family_history = st.selectbox("πŸ‘¨β€πŸ‘©β€πŸ‘§ Family history of mental health issues?", ("Yes", "No"))
80
- sleep = st.number_input("😴 Sleep hours per day", min_value=4, max_value=10)
81
- Diet = st.selectbox("🍽️ Diet quality", ("Good", "Average", "Poor"))
82
-
83
- with col2:
84
- stress = st.slider("😰 Stress levels (1-10)", min_value=0, max_value=10)
85
- physical_activity = st.number_input("πŸƒ Physical activity (minutes/day)", min_value=0, max_value=180)
86
- social_interaction = st.slider("πŸ—£οΈ Social interaction level (1-10)", min_value=0, max_value=10)
87
-
88
- # Center the submit button
89
- st.markdown('<div class="center-button">', unsafe_allow_html=True)
90
- submitted = st.form_submit_button("πŸ” Predict")
91
- st.markdown('</div>', unsafe_allow_html=True)
92
-
93
-
94
- df = pd.DataFrame([[work_hours, Family_history, sleep, stress,
95
- physical_activity, social_interaction, Diet]],
96
- columns=['Work Hours', 'Family History', 'Sleep Hours',
97
- 'Stress Level', 'Physical Activity',
98
- 'Social Interaction', 'Diet Quality'])
99
- # Model prediction
100
- if submitted:
101
- with open("encoding.pkl", 'rb') as file:
102
- encode = pickle.load(file)
103
- with open("model.pkl", "rb") as file:
104
- model = pickle.load(file)
105
- with open("pip.pkl",'rb') as file:
106
- pipe=pickle.load(file)
107
-
108
- transformed_df = pipe.transform(df)
109
- prediction = model.predict(transformed_df)[0]
110
-
111
- # Output results
112
- if prediction == 1:
113
- st.warning("⚠️ You may be at risk for mental health issues. It's recommended to take some self-care actions.")
114
- else:
115
- st.success("βœ… You're doing well! Keep up the good habits.")
116
-
117
- # Personalized Tips
118
- st.markdown("### πŸ’‘ Personalized Tips to Boost Your Mental Health")
119
- tips = []
120
-
121
- if Diet != "Good":
122
- tips.append("🍎 **Eat a Nutrient-Rich Snack Daily** \nSupports brain health with omega-3s, vitamins, and minerals.")
123
-
124
- if stress > 6:
125
- tips.append("🧘 **Meditate or Stretch for 15 Minutes** \nEases anxiety and improves focus.")
126
- tips.append("🌬️ **Practice Deep Breathing for 10 Minutes** \nLowers stress and anxiety levels.")
127
- tips.append("🚰 **Drink Water & Take 5-Minute Breaks** \nHydration supports mental clarity.")
128
- tips.append("🎧 **Walk 30 Minutes Daily with Music** \nReduces stress and uplifts mood.")
129
-
130
- if sleep < 7:
131
- tips.append("πŸ›Œ **Set a Consistent Sleep Schedule (7–8 Hours)** \nImproves energy and stabilizes mood.")
132
-
133
- if work_hours > 50:
134
- tips.append("πŸ“… **Limit Work to 40–45 Hours Per Week** \nPrevents burnout and enhances productivity.")
135
-
136
- if social_interaction < 5:
137
- tips.append("πŸ‘₯ **Spend at Least 1 Hour Socializing Daily** \nBoosts emotional well-being and reduces isolation.")
138
-
139
- for tip in tips:
140
- st.markdown(f"<p>{tip}</p>", unsafe_allow_html=True)
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
+