saherPervaiz commited on
Commit
d457fe7
Β·
verified Β·
1 Parent(s): bab9c1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -56
app.py CHANGED
@@ -41,26 +41,6 @@ def provide_observed_advice(data):
41
  "Low engagement in extracurricular activities detected. Consider joining clubs, sports, or creative groups that interest you. Participating in such activities can enhance your social connections, improve self-esteem, and provide a healthy outlet for stress."
42
  )
43
 
44
- if data['academic_performance'] < 5:
45
- advice.append(
46
- "Low academic performance detected. Break study tasks into smaller, achievable goals, and create a distraction-free study environment. Seek help from teachers, peers, or online resources for difficult topics. Time management strategies can also help you stay on track."
47
- )
48
-
49
- if data['bullying'] > 7:
50
- advice.append(
51
- "Bullying is a serious issue that can affect mental health. Talk to a trusted adult, teacher, or counselor about your experience. Build a support network with friends and consider attending therapy sessions to regain confidence and develop coping mechanisms."
52
- )
53
-
54
- if data['sleep_quality'] < 5:
55
- advice.append(
56
- "Poor sleep quality detected. Establish a consistent bedtime routine and avoid screens before sleep. Create a calm sleeping environment and consider relaxation techniques like meditation or reading before bed."
57
- )
58
-
59
- if data['basic_needs'] < 5:
60
- advice.append(
61
- "Unmet basic needs detected. Address your primary needs by seeking help from local resources or organizations. Focus on creating a stable environment and prioritize your physical and emotional well-being."
62
- )
63
-
64
  return advice
65
 
66
  def fetch_mental_health_articles():
@@ -74,12 +54,37 @@ def fetch_mental_health_articles():
74
  return []
75
 
76
  def main():
77
- st.set_page_config(page_title="Student Health Advisory Assistant", layout="wide")
78
- st.title("πŸ” Analyze Your Well-being")
79
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
81
  if uploaded_file:
82
  df = load_data(uploaded_file)
 
83
  st.write("### Dataset Preview:")
84
  st.dataframe(df.head())
85
 
@@ -102,39 +107,52 @@ def main():
102
  st.warning("The dataset contains missing values. Rows with missing values will be skipped.")
103
  df = df.dropna()
104
 
105
- st.markdown("### Select a Row for Analysis")
106
- selected_row = st.selectbox(
107
- "Select a row (based on index) to analyze:",
108
- options=df.index,
109
- format_func=lambda x: f"Row {x} - Stress Level: {df.loc[x, 'stress_level']}, Anxiety: {df.loc[x, 'anxiety_level']} (Depression: {df.loc[x, 'depression']})",
110
- )
111
-
112
- # Extract data for the selected row
113
- row_data = df.loc[selected_row].to_dict()
114
-
115
- # Show extracted details
116
- st.write("### Selected User Details:")
117
- st.json(row_data)
118
-
119
- # Generate advice
120
- st.subheader("πŸ”” Health Advice Based on Observations")
121
- advice = provide_observed_advice(row_data)
122
- if advice:
123
- for i, tip in enumerate(advice, 1):
124
- st.write(f"πŸ“Œ **{i}.** {tip}")
125
- else:
126
- st.warning("No specific advice available based on this user's data.")
127
-
128
- # Fetch and display mental health articles
129
- st.subheader("πŸ“° Mental Health Resources")
130
- articles = fetch_mental_health_articles()
131
- if articles:
132
- for article in articles:
133
- st.write(f"**{article['title']}**")
134
- st.write(f"{article['description']}")
135
- st.write(f"[Read more]({article['url']})")
136
- else:
137
- st.write("No articles available at the moment.")
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  if __name__ == "__main__":
140
  main()
 
41
  "Low engagement in extracurricular activities detected. Consider joining clubs, sports, or creative groups that interest you. Participating in such activities can enhance your social connections, improve self-esteem, and provide a healthy outlet for stress."
42
  )
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  return advice
45
 
46
  def fetch_mental_health_articles():
 
54
  return []
55
 
56
  def main():
57
+ # Set page config for a professional look
58
+ st.set_page_config(
59
+ page_title="Student Well-being Advisor",
60
+ page_icon="πŸ“Š",
61
+ layout="wide",
62
+ initial_sidebar_state="expanded",
63
+ )
64
+
65
+ # Sidebar
66
+ st.sidebar.title("Navigation")
67
+ st.sidebar.write("Use the sidebar to navigate through the app.")
68
+ st.sidebar.markdown("### πŸ“‚ Upload Data")
69
+ st.sidebar.write("Start by uploading your dataset for analysis.")
70
+ st.sidebar.markdown("### πŸ“Š Analysis & Advice")
71
+ st.sidebar.write("Get detailed insights and personalized advice.")
72
+
73
+ # Main Content
74
+ st.title("πŸŽ“ Student Well-being Advisor")
75
+ st.subheader("Analyze data and provide professional mental health recommendations.")
76
+ st.write(
77
+ """
78
+ This app helps identify areas of concern in students' well-being and provides personalized advice based on their responses.
79
+ """
80
+ )
81
+
82
+ # File Upload
83
+ st.markdown("## πŸ“‚ Upload Your Dataset")
84
  uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
85
  if uploaded_file:
86
  df = load_data(uploaded_file)
87
+ st.success("Dataset uploaded successfully!")
88
  st.write("### Dataset Preview:")
89
  st.dataframe(df.head())
90
 
 
107
  st.warning("The dataset contains missing values. Rows with missing values will be skipped.")
108
  df = df.dropna()
109
 
110
+ # Tabs for better organization
111
+ tab1, tab2, tab3 = st.tabs(["🏠 Home", "πŸ“Š Analysis", "πŸ“° Resources"])
112
+
113
+ with tab1:
114
+ st.write("### Welcome to the Well-being Advisor!")
115
+ st.write(
116
+ """
117
+ Use the tabs to explore data, generate advice, and access mental health resources.
118
+ """
119
+ )
120
+
121
+ with tab2:
122
+ st.markdown("### πŸ“Š Select a Row for Analysis")
123
+ selected_row = st.selectbox(
124
+ "Select a row (based on index) to analyze:",
125
+ options=df.index,
126
+ format_func=lambda x: f"Row {x} - Stress Level: {df.loc[x, 'stress_level']}, Anxiety: {df.loc[x, 'anxiety_level']} (Depression: {df.loc[x, 'depression']})",
127
+ )
128
+
129
+ # Extract data for the selected row
130
+ row_data = df.loc[selected_row].to_dict()
131
+
132
+ # Show extracted details
133
+ st.write("### Selected User Details:")
134
+ st.json(row_data)
135
+
136
+ # Generate advice
137
+ st.subheader("πŸ”” Health Advice Based on Observations")
138
+ advice = provide_observed_advice(row_data)
139
+ if advice:
140
+ for i, tip in enumerate(advice, 1):
141
+ st.write(f"πŸ“Œ **{i}.** {tip}")
142
+ else:
143
+ st.warning("No specific advice available based on this user's data.")
144
+
145
+ with tab3:
146
+ # Fetch and display mental health articles
147
+ st.subheader("πŸ“° Mental Health Resources")
148
+ articles = fetch_mental_health_articles()
149
+ if articles:
150
+ for article in articles:
151
+ st.write(f"**{article['title']}**")
152
+ st.write(f"{article['description']}")
153
+ st.write(f"[Read more]({article['url']})")
154
+ else:
155
+ st.write("No articles available at the moment.")
156
 
157
  if __name__ == "__main__":
158
  main()