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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -40
app.py CHANGED
@@ -9,42 +9,9 @@ news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API
9
  def load_data(file):
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
- return advice
45
-
46
- def fetch_mental_health_articles():
47
- url = f"https://newsapi.org/v2/everything?q=mental+health&apiKey={news_api_key}"
48
  response = requests.get(url)
49
  if response.status_code == 200:
50
  articles = response.json().get('articles', [])
@@ -53,6 +20,36 @@ def fetch_mental_health_articles():
53
  st.error("Failed to fetch news articles. Please check your API key or try again later.")
54
  return []
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def main():
57
  # Set page config for a professional look
58
  st.set_page_config(
@@ -133,9 +130,9 @@ def main():
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}")
@@ -145,7 +142,7 @@ def main():
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']}**")
 
9
  def load_data(file):
10
  return pd.read_csv(file)
11
 
12
+ def fetch_health_articles(query):
13
+ # Fetch mental health articles related to the query
14
+ url = f"https://newsapi.org/v2/everything?q={query}&apiKey={news_api_key}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  response = requests.get(url)
16
  if response.status_code == 200:
17
  articles = response.json().get('articles', [])
 
20
  st.error("Failed to fetch news articles. Please check your API key or try again later.")
21
  return []
22
 
23
+ def provide_advice_from_articles(data):
24
+ advice = []
25
+
26
+ # Use user data to fetch relevant health advice based on depression, anxiety, stress, etc.
27
+ if data['depression'] > 7:
28
+ advice.append("Searching for articles related to high depression...")
29
+ articles = fetch_health_articles("high depression")
30
+ for article in articles:
31
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
32
+
33
+ elif data['anxiety_level'] > 7:
34
+ advice.append("Searching for articles related to high anxiety...")
35
+ articles = fetch_health_articles("high anxiety")
36
+ for article in articles:
37
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
38
+
39
+ elif data['stress_level'] > 7:
40
+ advice.append("Searching for articles related to high stress...")
41
+ articles = fetch_health_articles("high stress")
42
+ for article in articles:
43
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
44
+
45
+ else:
46
+ advice.append("Searching for general health advice articles...")
47
+ articles = fetch_health_articles("mental health")
48
+ for article in articles:
49
+ advice.append(f"**{article['title']}**\n{article['description']}\n[Read more]({article['url']})")
50
+
51
+ return advice
52
+
53
  def main():
54
  # Set page config for a professional look
55
  st.set_page_config(
 
130
  st.write("### Selected User Details:")
131
  st.json(row_data)
132
 
133
+ # Fetch and display health advice from articles
134
+ st.subheader("πŸ”” Health Advice Based on Articles")
135
+ advice = provide_advice_from_articles(row_data)
136
  if advice:
137
  for i, tip in enumerate(advice, 1):
138
  st.write(f"πŸ“Œ **{i}.** {tip}")
 
142
  with tab3:
143
  # Fetch and display mental health articles
144
  st.subheader("πŸ“° Mental Health Resources")
145
+ articles = fetch_health_articles("mental health")
146
  if articles:
147
  for article in articles:
148
  st.write(f"**{article['title']}**")