Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import requests
|
4 |
|
5 |
# Set the GROC API Key directly in the code
|
6 |
-
GROC_API_KEY = "
|
7 |
|
8 |
# Function to load and preprocess data
|
9 |
@st.cache_data
|
@@ -11,47 +10,32 @@ def load_data(file):
|
|
11 |
df = pd.read_csv(file)
|
12 |
return df
|
13 |
|
14 |
-
# Function to provide detailed health advice based on
|
15 |
def provide_observed_advice(data):
|
16 |
advice = []
|
17 |
|
18 |
-
# High depression
|
19 |
if data['depression'] > 7 and data['anxiety'] > 7:
|
20 |
-
advice.append("You seem to be experiencing high levels of both depression and anxiety. It
|
21 |
|
22 |
-
# Moderate depression
|
23 |
elif data['depression'] > 5 or data['anxiety'] > 5:
|
24 |
-
advice.append("You are showing moderate levels of depression
|
25 |
|
26 |
-
# High isolation
|
27 |
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
|
28 |
-
advice.append("It seems
|
29 |
|
30 |
-
#
|
31 |
if data['future_insecurity'] > 7:
|
32 |
-
advice.append("You are feeling a significant amount of insecurity about the future. It
|
33 |
|
34 |
-
# Overall
|
35 |
if data['stress_relief_activities'] < 5:
|
36 |
-
advice.append("Your engagement in stress-relief activities is quite low. It
|
37 |
|
38 |
return advice
|
39 |
|
40 |
-
# Function to fetch health articles from the GROC API based on the query
|
41 |
-
def get_health_articles(query):
|
42 |
-
url = f"https://api.groc.com/search?q={query}"
|
43 |
-
headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
|
44 |
-
|
45 |
-
try:
|
46 |
-
response = requests.get(url, headers=headers)
|
47 |
-
response.raise_for_status()
|
48 |
-
data = response.json() # Assuming the API returns JSON
|
49 |
-
articles = [{"title": item["title"], "url": item["url"]} for item in data.get("results", [])]
|
50 |
-
return articles
|
51 |
-
except requests.exceptions.RequestException as e:
|
52 |
-
st.error(f"Error fetching articles: {e}")
|
53 |
-
return []
|
54 |
-
|
55 |
# Streamlit app layout
|
56 |
def main():
|
57 |
st.title("Student Health Advisory Assistant")
|
@@ -85,22 +69,12 @@ def main():
|
|
85 |
"stress_relief_activities": stress_relief_activities,
|
86 |
}
|
87 |
|
88 |
-
# Provide advice based on
|
89 |
if st.button("Get Observed Advice"):
|
90 |
st.subheader("Health Advice Based on Observations")
|
91 |
advice = provide_observed_advice(user_data)
|
92 |
for i, tip in enumerate(advice, 1):
|
93 |
st.write(f"{i}. {tip}")
|
94 |
|
95 |
-
# Fetch related health articles based on user input
|
96 |
-
st.subheader("Related Health Articles")
|
97 |
-
query = f"mental health anxiety depression isolation stress relief"
|
98 |
-
articles = get_health_articles(query)
|
99 |
-
if articles:
|
100 |
-
for article in articles:
|
101 |
-
st.write(f"- [{article['title']}]({article['url']})")
|
102 |
-
else:
|
103 |
-
st.write("No articles found. Please check your API key or internet connection.")
|
104 |
-
|
105 |
if __name__ == "__main__":
|
106 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
# Set the GROC API Key directly in the code
|
5 |
+
GROC_API_KEY = "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" # Replace with your actual GROC API key
|
6 |
|
7 |
# Function to load and preprocess data
|
8 |
@st.cache_data
|
|
|
10 |
df = pd.read_csv(file)
|
11 |
return df
|
12 |
|
13 |
+
# Function to provide detailed health advice based on user data
|
14 |
def provide_observed_advice(data):
|
15 |
advice = []
|
16 |
|
17 |
+
# High depression and anxiety with low stress-relief activities
|
18 |
if data['depression'] > 7 and data['anxiety'] > 7:
|
19 |
+
advice.append("You seem to be experiencing high levels of both depression and anxiety. It's important to consider professional mental health support. You might also benefit from engaging in calming activities like deep breathing, mindfulness, or yoga.")
|
20 |
|
21 |
+
# Moderate depression or anxiety
|
22 |
elif data['depression'] > 5 or data['anxiety'] > 5:
|
23 |
+
advice.append("You are showing moderate levels of depression or anxiety. It would be helpful to develop healthy coping strategies like maintaining a regular sleep schedule, engaging in physical activity, and reaching out to friends or family for support.")
|
24 |
|
25 |
+
# High isolation and low stress-relief activities
|
26 |
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
|
27 |
+
advice.append("It seems you are feeling isolated, and your engagement in stress-relief activities is low. It's important to connect with friends or join community groups. Incorporate activities that help alleviate stress, such as walking, journaling, or meditation.")
|
28 |
|
29 |
+
# High future insecurity
|
30 |
if data['future_insecurity'] > 7:
|
31 |
+
advice.append("You are feeling a significant amount of insecurity about the future. It can be helpful to break down your larger goals into smaller, manageable tasks. Seeking career counseling or mentorship could provide valuable guidance and reduce anxiety about the future.")
|
32 |
|
33 |
+
# Overall low engagement in stress-relief activities
|
34 |
if data['stress_relief_activities'] < 5:
|
35 |
+
advice.append("Your engagement in stress-relief activities is quite low. It's essential to engage in activities that reduce stress and promote mental wellness, such as hobbies, physical exercise, and relaxation techniques like deep breathing or yoga.")
|
36 |
|
37 |
return advice
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Streamlit app layout
|
40 |
def main():
|
41 |
st.title("Student Health Advisory Assistant")
|
|
|
69 |
"stress_relief_activities": stress_relief_activities,
|
70 |
}
|
71 |
|
72 |
+
# Provide advice based on user inputs
|
73 |
if st.button("Get Observed Advice"):
|
74 |
st.subheader("Health Advice Based on Observations")
|
75 |
advice = provide_observed_advice(user_data)
|
76 |
for i, tip in enumerate(advice, 1):
|
77 |
st.write(f"{i}. {tip}")
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
if __name__ == "__main__":
|
80 |
main()
|