saherPervaiz commited on
Commit
a4b12c8
Β·
verified Β·
1 Parent(s): 67efa1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -61
app.py CHANGED
@@ -21,64 +21,40 @@ def fetch_health_articles(query):
21
  st.error("Failed to fetch news articles. Please check your API key or try again later.")
22
  return []
23
 
24
- def provide_advice_from_articles(data):
25
  advice = []
26
- # High depression
27
- if data['depression'] > 7:
28
- advice.append("πŸ”΄ **High Depression Levels Detected**")
29
- advice.append("""
30
- Depression is a serious condition that affects many aspects of life. If you are experiencing high levels of depression, it is important to seek professional help.
31
- Here are some key steps that might help:
32
- - **Consider therapy**: Cognitive Behavioral Therapy (CBT) is proven to be effective for managing depression.
33
- - **Stay active**: Exercise can boost your mood and reduce stress.
34
- - **Reach out to loved ones**: Isolation can worsen depression, so staying connected with friends and family is crucial.
35
- - **Practice mindfulness**: Techniques such as deep breathing and meditation can be effective in managing depressive symptoms.
36
- """)
37
- articles = fetch_health_articles("high depression")
38
- for article in articles:
39
- advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
40
 
41
- # High anxiety
42
- elif data['anxiety_level'] > 7:
43
- advice.append("🟠 **High Anxiety Levels Detected**")
44
- advice.append("""
45
- Anxiety can cause significant distress and impact daily life. Addressing anxiety early can help you regain control over your well-being.
46
- Here's how you can manage anxiety:
47
- - **Breathing exercises**: Slow, deep breaths can help calm the mind and body.
48
- - **Progressive muscle relaxation**: Tense and then relax different muscle groups to reduce physical tension.
49
- - **Limit stimulants**: Reduce caffeine and sugar, which can increase anxiety.
50
- - **Journaling**: Writing down your thoughts can help process feelings of anxiety.
51
- """)
52
- articles = fetch_health_articles("high anxiety")
53
  for article in articles:
54
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
55
-
56
- # High stress
57
- elif data['stress_level'] > 7:
58
- advice.append("🟑 **High Stress Levels Detected**")
59
- advice.append("""
60
- Prolonged stress can have adverse effects on both mental and physical health. Managing stress is crucial for maintaining balance and well-being.
61
- Consider these strategies:
62
- - **Time management**: Prioritize tasks and break them down into manageable steps to avoid feeling overwhelmed.
63
- - **Physical activity**: Exercise can act as a natural stress reliever.
64
- - **Relaxation techniques**: Meditation, yoga, or simply taking breaks during the day can reduce stress.
65
- - **Sleep hygiene**: Ensure you're getting enough restful sleep by maintaining a regular sleep schedule.
66
- """)
67
- articles = fetch_health_articles("high stress")
68
  for article in articles:
69
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
70
-
71
- # General mental health advice
72
  else:
73
- advice.append("🟒 **General Health Advice**")
74
- advice.append("""
75
- Maintaining mental health is an ongoing process, and it’s important to integrate healthy habits into daily life. Here are some general tips:
76
- - **Exercise regularly**: Physical activity can significantly boost mood and mental clarity.
77
- - **Eat a balanced diet**: Nutrition plays a vital role in mental well-being.
78
- - **Practice gratitude**: Reflecting on things you’re grateful for can shift your focus from stress to positivity.
79
- - **Social support**: Stay connected with family and friends for emotional support.
80
- """)
81
- articles = fetch_health_articles("mental health")
 
 
 
 
 
 
82
  for article in articles:
83
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
84
 
@@ -98,8 +74,8 @@ def plot_graphs(data):
98
 
99
  def main():
100
  st.set_page_config(
101
- page_title="Student Well-being Advisor",
102
- page_icon="πŸ“Š",
103
  layout="wide",
104
  initial_sidebar_state="expanded",
105
  )
@@ -111,10 +87,10 @@ def main():
111
  st.sidebar.markdown("### πŸ“Š Analysis & Advice")
112
  st.sidebar.write("Get detailed insights and personalized advice.")
113
 
114
- st.title("πŸŽ“ Student Well-being Advisor")
115
- st.subheader("Analyze data and provide professional mental health recommendations.")
116
  st.write("""
117
- This app helps identify areas of concern in students' well-being and provides personalized advice based on their responses.
118
  """)
119
 
120
  st.markdown("## πŸ“‚ Upload Your Dataset")
@@ -145,7 +121,7 @@ def main():
145
  tab1, tab2, tab3 = st.tabs(["🏠 Home", "πŸ“Š Analysis", "πŸ“° Resources"])
146
 
147
  with tab1:
148
- st.write("### Welcome to the Well-being Advisor!")
149
  st.write("""
150
  Use the tabs to explore data, generate advice, and access mental health resources.
151
  """)
@@ -161,20 +137,20 @@ def main():
161
  st.write("### Selected User Details:")
162
  st.json(row_data)
163
 
164
- st.subheader("πŸ”” Health Advice Based on Articles")
165
- advice = provide_advice_from_articles(row_data)
166
  if advice:
167
  for i, tip in enumerate(advice, 1):
168
  st.write(f"πŸ“Œ **{i}.** {tip}")
169
  else:
170
- st.warning("No specific advice available based on this user's data.")
171
 
172
  # Include graphs in analysis tab
173
  plot_graphs(df)
174
 
175
  with tab3:
176
  st.subheader("πŸ“° Mental Health Resources")
177
- articles = fetch_health_articles("mental health")
178
  if articles:
179
  for article in articles:
180
  st.write(f"**{article['title']}**")
 
21
  st.error("Failed to fetch news articles. Please check your API key or try again later.")
22
  return []
23
 
24
+ def provide_advice_from_selected_row(data):
25
  advice = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ stress_level = data['stress_level']
28
+ anxiety_level = data['anxiety_level']
29
+ depression_level = data['depression']
30
+
31
+ # Generate advice based on the stress level of the selected row
32
+ if stress_level > 7:
33
+ advice.append("πŸ”΄ **High Stress Levels Detected**: It's critical to manage stress effectively. Please explore the following articles to help you manage stress:")
34
+ articles = fetch_health_articles("high stress management")
 
 
 
 
35
  for article in articles:
36
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
37
+ elif stress_level > 4:
38
+ advice.append("🟑 **Moderate Stress Levels**: It's important to manage moderate stress. Here are some helpful articles and tips:")
39
+ articles = fetch_health_articles("moderate stress management")
 
 
 
 
 
 
 
 
 
 
40
  for article in articles:
41
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
 
 
42
  else:
43
+ advice.append("🟒 **Low Stress Levels**: Great! You're in a good place, but it's still important to maintain healthy stress management. Here are some resources to help:")
44
+ articles = fetch_health_articles("stress relief techniques")
45
+ for article in articles:
46
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
47
+
48
+ # Additional advice based on anxiety and depression levels
49
+ if anxiety_level > 7:
50
+ advice.append("\nπŸ”΄ **High Anxiety Levels**: Managing anxiety is crucial. Here are some resources to help manage anxiety:")
51
+ articles = fetch_health_articles("high anxiety management")
52
+ for article in articles:
53
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
54
+
55
+ if depression_level > 7:
56
+ advice.append("\nπŸ”΄ **High Depression Levels**: It's important to seek professional support for depression. Here are some helpful resources:")
57
+ articles = fetch_health_articles("high depression management")
58
  for article in articles:
59
  advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
60
 
 
74
 
75
  def main():
76
  st.set_page_config(
77
+ page_title="Stress Management Advisor",
78
+ page_icon="🧠",
79
  layout="wide",
80
  initial_sidebar_state="expanded",
81
  )
 
87
  st.sidebar.markdown("### πŸ“Š Analysis & Advice")
88
  st.sidebar.write("Get detailed insights and personalized advice.")
89
 
90
+ st.title("πŸŽ“ Stress Management Advisor")
91
+ st.subheader("Analyze stress levels and receive professional stress management recommendations.")
92
  st.write("""
93
+ This app helps identify areas of concern related to stress in individuals and provides personalized advice based on their responses.
94
  """)
95
 
96
  st.markdown("## πŸ“‚ Upload Your Dataset")
 
121
  tab1, tab2, tab3 = st.tabs(["🏠 Home", "πŸ“Š Analysis", "πŸ“° Resources"])
122
 
123
  with tab1:
124
+ st.write("### Welcome to the Stress Management Advisor!")
125
  st.write("""
126
  Use the tabs to explore data, generate advice, and access mental health resources.
127
  """)
 
137
  st.write("### Selected User Details:")
138
  st.json(row_data)
139
 
140
+ st.subheader("πŸ”” Health Advice Based on Selected Row")
141
+ advice = provide_advice_from_selected_row(row_data)
142
  if advice:
143
  for i, tip in enumerate(advice, 1):
144
  st.write(f"πŸ“Œ **{i}.** {tip}")
145
  else:
146
+ st.warning("No specific advice available based on this user's stress level.")
147
 
148
  # Include graphs in analysis tab
149
  plot_graphs(df)
150
 
151
  with tab3:
152
  st.subheader("πŸ“° Mental Health Resources")
153
+ articles = fetch_health_articles("stress relief")
154
  if articles:
155
  for article in articles:
156
  st.write(f"**{article['title']}**")