Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
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 |
-
|
57 |
-
|
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("π’ **
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
""
|
81 |
-
articles = fetch_health_articles("
|
|
|
|
|
|
|
|
|
|
|
|
|
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="
|
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("π
|
115 |
-
st.subheader("Analyze
|
116 |
st.write("""
|
117 |
-
This app helps identify areas of concern in
|
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
|
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
|
165 |
-
advice =
|
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
|
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("
|
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']}**")
|