Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import streamlit as st
|
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
|
6 |
-
# API Key for fetching mental health articles
|
7 |
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
|
8 |
|
9 |
@st.cache_data
|
@@ -11,112 +10,73 @@ def load_data(file):
|
|
11 |
return pd.read_csv(file)
|
12 |
|
13 |
def provide_observed_advice(data):
|
14 |
-
"""Generate detailed advice based on the user's data."""
|
15 |
advice = []
|
16 |
|
17 |
-
|
18 |
-
if data['depression'] > 7 or data['anxiety_level'] > 7:
|
19 |
advice.append(
|
20 |
-
"You are experiencing high levels of depression
|
21 |
-
"Please consider scheduling an appointment with a mental health professional. Additionally, practice mindfulness or meditation daily, "
|
22 |
-
"engage in hobbies you enjoy, and spend time in nature to help reduce negative emotions."
|
23 |
)
|
24 |
elif data['depression'] > 5 or data['anxiety_level'] > 5:
|
25 |
advice.append(
|
26 |
-
"
|
27 |
-
"such as walking, yoga, or light exercise. Build a support system by reaching out to trusted friends or family members. "
|
28 |
-
"Consider journaling your thoughts or keeping a gratitude diary to refocus your mind on positive aspects of your life."
|
29 |
)
|
30 |
|
31 |
-
if data['
|
32 |
-
advice.append(
|
33 |
-
"High stress levels detected. Stress can negatively affect your physical and mental health. To manage stress effectively, "
|
34 |
-
"practice relaxation techniques such as deep breathing, progressive muscle relaxation, or guided imagery. "
|
35 |
-
"Identify your stressors and try to address them one by one. Seek professional counseling if stress becomes overwhelming."
|
36 |
-
)
|
37 |
-
|
38 |
-
if data['mental_health_history'] > 5:
|
39 |
-
advice.append(
|
40 |
-
"Your mental health history indicates potential ongoing challenges. Consistent therapy or counseling might provide the support you need. "
|
41 |
-
"Stay proactive in tracking your mood changes and avoid isolating yourself when you're feeling low."
|
42 |
-
)
|
43 |
-
|
44 |
-
# Physical Health Advice
|
45 |
-
if data['headache'] > 5:
|
46 |
-
advice.append(
|
47 |
-
"Frequent headaches reported. Ensure you’re staying hydrated and maintaining a balanced diet. Avoid prolonged screen time "
|
48 |
-
"and practice proper posture to reduce physical strain. If headaches persist, consult a doctor to rule out underlying conditions."
|
49 |
-
)
|
50 |
-
|
51 |
-
if data['blood_pressure'] > 5:
|
52 |
-
advice.append(
|
53 |
-
"Elevated blood pressure detected. Reduce your salt intake and focus on a heart-healthy diet rich in fruits, vegetables, and lean proteins. "
|
54 |
-
"Engage in light exercises like walking or swimming, and monitor your blood pressure regularly. Consult a doctor for long-term management strategies."
|
55 |
-
)
|
56 |
-
|
57 |
-
if data['sleep_quality'] < 5:
|
58 |
advice.append(
|
59 |
-
"
|
60 |
-
"Try relaxation techniques like reading or listening to soothing music before bed. Seek medical advice if sleep problems persist."
|
61 |
)
|
62 |
|
63 |
-
if data['
|
64 |
advice.append(
|
65 |
-
"
|
66 |
-
"Practice deep breathing exercises or try yoga to improve lung function. Consider consulting a pulmonologist for further evaluation."
|
67 |
)
|
68 |
|
69 |
-
|
70 |
-
if data['noise_level'] > 7:
|
71 |
advice.append(
|
72 |
-
"High
|
73 |
-
"Spend some time in peaceful locations, such as parks or libraries, to recharge mentally."
|
74 |
)
|
75 |
|
76 |
-
if data['
|
77 |
advice.append(
|
78 |
-
"
|
79 |
-
"Consider reaching out to local authorities or organizations for assistance in addressing safety concerns."
|
80 |
)
|
81 |
|
82 |
-
|
83 |
-
if data['study_load'] > 7:
|
84 |
advice.append(
|
85 |
-
"
|
86 |
-
"Avoid multitasking and focus on one task at a time to improve efficiency. Consider seeking help from teachers or peers if you feel overwhelmed."
|
87 |
)
|
88 |
|
89 |
-
if data['
|
90 |
advice.append(
|
91 |
-
"
|
92 |
-
"Research potential career paths, network with professionals, and consider attending career counseling for guidance."
|
93 |
)
|
94 |
|
95 |
-
if data['
|
96 |
-
advice.append(
|
97 |
-
"Low social support detected. Building meaningful connections can significantly improve your well-being. "
|
98 |
-
"Join social groups, clubs, or community activities that align with your interests. Don’t hesitate to reach out to friends or family for emotional support."
|
99 |
-
)
|
100 |
-
|
101 |
-
if data['peer_pressure'] > 7:
|
102 |
advice.append(
|
103 |
-
"
|
104 |
-
"and remember that it's okay to say no. Surround yourself with individuals who respect your boundaries."
|
105 |
)
|
106 |
|
107 |
-
if data['
|
108 |
advice.append(
|
109 |
-
"
|
110 |
-
"reduce stress, and expand your social circle. Consider trying out an activity that interests you."
|
111 |
)
|
112 |
|
113 |
return advice
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
def main():
|
116 |
-
st.set_page_config(page_title="Student
|
117 |
st.title("🔍 Analyze Your Well-being")
|
118 |
|
119 |
-
# File uploader
|
120 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
121 |
if uploaded_file:
|
122 |
df = load_data(uploaded_file)
|
@@ -125,11 +85,11 @@ def main():
|
|
125 |
|
126 |
# Validate dataset columns
|
127 |
required_columns = [
|
128 |
-
'anxiety_level', 'self_esteem', 'mental_health_history', 'depression',
|
129 |
-
'headache', 'blood_pressure', 'sleep_quality', 'breathing_problem',
|
130 |
-
'noise_level', 'living_conditions', 'safety', 'basic_needs',
|
131 |
-
'academic_performance', 'study_load', 'teacher_student_relationship',
|
132 |
-
'future_career_concerns', 'social_support', 'peer_pressure',
|
133 |
'extracurricular_activities', 'bullying', 'stress_level'
|
134 |
]
|
135 |
missing_columns = [col for col in required_columns if col not in df.columns]
|
@@ -146,7 +106,7 @@ def main():
|
|
146 |
selected_row = st.selectbox(
|
147 |
"Select a row (based on index) to analyze:",
|
148 |
options=df.index,
|
149 |
-
format_func=lambda x: f"Row {x} -
|
150 |
)
|
151 |
|
152 |
# Extract data for the selected row
|
@@ -157,7 +117,7 @@ def main():
|
|
157 |
st.json(row_data)
|
158 |
|
159 |
# Generate advice
|
160 |
-
st.subheader("🔔
|
161 |
advice = provide_observed_advice(row_data)
|
162 |
if advice:
|
163 |
for i, tip in enumerate(advice, 1):
|
@@ -165,5 +125,16 @@ def main():
|
|
165 |
else:
|
166 |
st.warning("No specific advice available based on this user's data.")
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
if __name__ == "__main__":
|
169 |
main()
|
|
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
|
|
|
6 |
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
|
7 |
|
8 |
@st.cache_data
|
|
|
10 |
return pd.read_csv(file)
|
11 |
|
12 |
def provide_observed_advice(data):
|
|
|
13 |
advice = []
|
14 |
|
15 |
+
if data['depression'] > 7 and data['anxiety_level'] > 7:
|
|
|
16 |
advice.append(
|
17 |
+
"You are experiencing high levels of both depression and anxiety. Seek professional support from a therapist or counselor. Incorporate mindfulness activities such as meditation, deep breathing, or progressive relaxation. Surround yourself with a supportive environment and engage in regular self-care activities."
|
|
|
|
|
18 |
)
|
19 |
elif data['depression'] > 5 or data['anxiety_level'] > 5:
|
20 |
advice.append(
|
21 |
+
"Moderate levels of depression or anxiety detected. Regular exercise, consistent sleep schedules, and maintaining a balanced diet can help. Journaling or talking to a friend can help you process your emotions. Reach out to a mental health professional if needed."
|
|
|
|
|
22 |
)
|
23 |
|
24 |
+
if data['peer_pressure'] > 7 and data['social_support'] < 5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
advice.append(
|
26 |
+
"You may be feeling overwhelmed by peer pressure and lack social support. Focus on building healthy relationships with supportive individuals. Join groups or communities that align with your values, and avoid situations where you feel pressured to conform."
|
|
|
27 |
)
|
28 |
|
29 |
+
if data['future_career_concerns'] > 7:
|
30 |
advice.append(
|
31 |
+
"You have significant concerns about your future career. Break your long-term career goals into manageable tasks. Seek guidance from a career counselor or mentor, and participate in workshops or events that enhance your professional skills."
|
|
|
32 |
)
|
33 |
|
34 |
+
if data['stress_level'] > 7:
|
|
|
35 |
advice.append(
|
36 |
+
"High stress levels detected. Engage in activities that promote relaxation, such as yoga, journaling, or spending time in nature. Consider reducing workload or delegating responsibilities where possible. Don't hesitate to consult a professional for stress management strategies."
|
|
|
37 |
)
|
38 |
|
39 |
+
if data['extracurricular_activities'] < 5:
|
40 |
advice.append(
|
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():
|
67 |
+
url = f"https://newsapi.org/v2/everything?q=mental+health&apiKey={news_api_key}"
|
68 |
+
response = requests.get(url)
|
69 |
+
if response.status_code == 200:
|
70 |
+
articles = response.json().get('articles', [])
|
71 |
+
return articles[:5] # Return the top 5 articles
|
72 |
+
else:
|
73 |
+
st.error("Failed to fetch news articles. Please check your API key or try again later.")
|
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)
|
|
|
85 |
|
86 |
# Validate dataset columns
|
87 |
required_columns = [
|
88 |
+
'anxiety_level', 'self_esteem', 'mental_health_history', 'depression',
|
89 |
+
'headache', 'blood_pressure', 'sleep_quality', 'breathing_problem',
|
90 |
+
'noise_level', 'living_conditions', 'safety', 'basic_needs',
|
91 |
+
'academic_performance', 'study_load', 'teacher_student_relationship',
|
92 |
+
'future_career_concerns', 'social_support', 'peer_pressure',
|
93 |
'extracurricular_activities', 'bullying', 'stress_level'
|
94 |
]
|
95 |
missing_columns = [col for col in required_columns if col not in df.columns]
|
|
|
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
|
|
|
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):
|
|
|
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()
|