saherPervaiz commited on
Commit
71be87b
·
verified ·
1 Parent(s): 5117e78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -35
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import requests
4
  import os
 
5
 
6
  # Retrieve the GROC API Key from environment variable
7
- GROC_API_KEY = "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"
8
 
9
  # Check if the API key is missing
10
  if not GROC_API_KEY:
@@ -16,36 +16,33 @@ else:
16
  df = pd.read_csv(file)
17
  return df
18
 
19
- # Function to provide detailed health advice
20
- def provide_detailed_advice(data):
21
  advice = []
22
 
23
- if data['depression'] > 7:
24
- advice.append("You have high levels of depression. Consider consulting a mental health professional. Practice self-care activities like mindfulness, journaling, and physical exercise.")
25
- elif data['depression'] > 5:
26
- advice.append("Your depression levels are moderate. Engage in uplifting activities, maintain a healthy routine, and seek social support.")
27
 
28
- if data['anxiety'] > 7:
29
- advice.append("High levels of anxiety detected. Use breathing exercises, yoga, and reduce caffeine intake. Consulting a therapist is highly recommended.")
30
- elif data['anxiety'] > 5:
31
- advice.append("Moderate anxiety levels observed. Focus on managing stress, maintaining proper sleep, and practicing relaxation techniques.")
32
 
33
- if data['isolation'] > 7:
34
- advice.append("You might be feeling isolated. Try joining community groups, reaching out to friends, or participating in social activities.")
35
- elif data['isolation'] > 5:
36
- advice.append("Moderate isolation detected. Schedule regular social interactions to maintain mental wellness.")
37
 
 
38
  if data['future_insecurity'] > 7:
39
- advice.append("You have significant concerns about the future. Break large goals into smaller tasks, and consider career counseling or mentorship.")
40
- elif data['future_insecurity'] > 5:
41
- advice.append("Moderate future insecurity observed. Building a concrete plan and seeking guidance from trusted professionals can help.")
42
 
 
43
  if data['stress_relief_activities'] < 5:
44
- advice.append("Low engagement in stress-relief activities. Incorporate activities like walking, meditation, or pursuing hobbies into your routine.")
45
 
46
  return advice
47
 
48
- # Function to fetch health articles using the GROC API
49
  def get_health_articles(query):
50
  url = f"https://api.groc.com/search?q={query}"
51
  headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
@@ -63,7 +60,7 @@ else:
63
  # Streamlit app layout
64
  def main():
65
  st.title("Student Health Advisory Assistant")
66
- st.subheader("Analyze your well-being and get advice")
67
 
68
  # File upload
69
  uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
@@ -93,22 +90,22 @@ else:
93
  "stress_relief_activities": stress_relief_activities,
94
  }
95
 
96
- # Provide advice
97
- if st.button("Get Detailed Advice"):
98
- st.subheader("Health Advice")
99
- advice = provide_detailed_advice(user_data)
100
  for i, tip in enumerate(advice, 1):
101
  st.write(f"{i}. {tip}")
102
 
103
- # Fetch articles from GROC API
104
- st.subheader("Related Health Articles")
105
- query = "mental health, stress relief, social well-being"
106
- articles = get_health_articles(query)
107
- if articles:
108
- for article in articles:
109
- st.write(f"- [{article['title']}]({article['url']})")
110
- else:
111
- st.write("No articles found. Please check your API key or internet connection.")
112
 
113
  if __name__ == "__main__":
114
  main()
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  import os
4
+ import requests
5
 
6
  # Retrieve the GROC API Key from environment variable
7
+ GROC_API_KEY = os.getenv("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")
8
 
9
  # Check if the API key is missing
10
  if not GROC_API_KEY:
 
16
  df = pd.read_csv(file)
17
  return df
18
 
19
+ # Function to provide detailed health advice based on model observation
20
+ def provide_observed_advice(data):
21
  advice = []
22
 
23
+ # High depression, anxiety, and low stress-relief activities may indicate a need for professional help
24
+ if data['depression'] > 7 and data['anxiety'] > 7:
25
+ advice.append("You seem to be experiencing high levels of both depression and anxiety. It is important to consider professional mental health support, such as therapy or counseling. Engage in calming activities like deep breathing, mindfulness, and yoga.")
 
26
 
27
+ # Moderate depression and anxiety levels can indicate stress but still manageable
28
+ elif data['depression'] > 5 or data['anxiety'] > 5:
29
+ advice.append("You are showing moderate levels of depression and/or anxiety. Focus on developing healthy coping strategies such as maintaining a regular sleep schedule, engaging in physical activity, and reaching out to friends or family for support.")
 
30
 
31
+ # High isolation combined with low engagement in stress-relief activities could suggest loneliness
32
+ if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
33
+ advice.append("It seems that you're feeling isolated, and your engagement in stress-relief activities is low. Try connecting with friends or a community group, and incorporate activities that help alleviate stress, such as walking, meditation, or journaling.")
 
34
 
35
+ # If future insecurity is high, career counseling might be helpful
36
  if data['future_insecurity'] > 7:
37
+ advice.append("You are feeling a significant amount of insecurity about the future. It might be helpful to break down your larger goals into smaller, manageable tasks. Seeking career counseling or mentorship could provide valuable guidance.")
 
 
38
 
39
+ # Overall, low levels of stress-relief activities are a concern
40
  if data['stress_relief_activities'] < 5:
41
+ advice.append("Your engagement in stress-relief activities is quite low. It is crucial to engage in activities that reduce stress and promote mental wellness, such as hobbies, physical exercise, or relaxation techniques.")
42
 
43
  return advice
44
 
45
+ # Function to fetch health articles from the GROC API based on the query
46
  def get_health_articles(query):
47
  url = f"https://api.groc.com/search?q={query}"
48
  headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
 
60
  # Streamlit app layout
61
  def main():
62
  st.title("Student Health Advisory Assistant")
63
+ st.subheader("Analyze your well-being and get personalized advice")
64
 
65
  # File upload
66
  uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
 
90
  "stress_relief_activities": stress_relief_activities,
91
  }
92
 
93
+ # Provide advice based on model observations
94
+ if st.button("Get Observed Advice"):
95
+ st.subheader("Health Advice Based on Observations")
96
+ advice = provide_observed_advice(user_data)
97
  for i, tip in enumerate(advice, 1):
98
  st.write(f"{i}. {tip}")
99
 
100
+ # Fetch related health articles based on user input
101
+ st.subheader("Related Health Articles")
102
+ query = f"mental health anxiety depression isolation stress relief"
103
+ articles = get_health_articles(query)
104
+ if articles:
105
+ for article in articles:
106
+ st.write(f"- [{article['title']}]({article['url']})")
107
+ else:
108
+ st.write("No articles found. Please check your API key or internet connection.")
109
 
110
  if __name__ == "__main__":
111
  main()