Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,44 +8,72 @@ def load_data(file):
|
|
8 |
df = pd.read_csv(file)
|
9 |
return df
|
10 |
|
11 |
-
# Function to provide
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
advice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return advice
|
23 |
|
24 |
-
#
|
25 |
-
def get_health_articles(query):
|
|
|
|
|
|
|
|
|
26 |
try:
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
except
|
33 |
st.error(f"Error fetching articles: {e}")
|
34 |
return []
|
35 |
|
36 |
# Streamlit app layout
|
37 |
def main():
|
38 |
st.title("Student Health Advisory Assistant")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# File upload
|
41 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
42 |
if uploaded_file:
|
43 |
df = load_data(uploaded_file)
|
|
|
44 |
st.dataframe(df.head())
|
45 |
|
46 |
-
# User input
|
47 |
-
st.header("Input Your
|
48 |
-
gender = st.selectbox("Gender",
|
49 |
age = st.slider("Age", 18, 35, step=1)
|
50 |
depression = st.slider("Depression Level (1-10)", 1, 10)
|
51 |
anxiety = st.slider("Anxiety Level (1-10)", 1, 10)
|
@@ -53,19 +81,33 @@ def main():
|
|
53 |
future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10)
|
54 |
stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10)
|
55 |
|
56 |
-
#
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
st.subheader("Health Advice")
|
59 |
-
advice =
|
60 |
-
|
61 |
-
|
62 |
-
st.write(advice)
|
63 |
|
|
|
64 |
st.subheader("Related Health Articles")
|
65 |
-
|
|
|
66 |
if articles:
|
67 |
for article in articles:
|
68 |
st.write(f"- [{article['title']}]({article['url']})")
|
|
|
|
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
main()
|
|
|
8 |
df = pd.read_csv(file)
|
9 |
return df
|
10 |
|
11 |
+
# Function to provide detailed health advice
|
12 |
+
def provide_detailed_advice(data):
|
13 |
+
advice = []
|
14 |
+
|
15 |
+
if data['depression'] > 7:
|
16 |
+
advice.append("You have high levels of depression. Consider consulting a mental health professional. Practice self-care activities like mindfulness, journaling, and physical exercise.")
|
17 |
+
elif data['depression'] > 5:
|
18 |
+
advice.append("Your depression levels are moderate. Engage in uplifting activities, maintain a healthy routine, and seek social support.")
|
19 |
+
|
20 |
+
if data['anxiety'] > 7:
|
21 |
+
advice.append("High levels of anxiety detected. Use breathing exercises, yoga, and reduce caffeine intake. Consulting a therapist is highly recommended.")
|
22 |
+
elif data['anxiety'] > 5:
|
23 |
+
advice.append("Moderate anxiety levels observed. Focus on managing stress, maintaining proper sleep, and practicing relaxation techniques.")
|
24 |
+
|
25 |
+
if data['isolation'] > 7:
|
26 |
+
advice.append("You might be feeling isolated. Try joining community groups, reaching out to friends, or participating in social activities.")
|
27 |
+
elif data['isolation'] > 5:
|
28 |
+
advice.append("Moderate isolation detected. Schedule regular social interactions to maintain mental wellness.")
|
29 |
+
|
30 |
+
if data['future_insecurity'] > 7:
|
31 |
+
advice.append("You have significant concerns about the future. Break large goals into smaller tasks, and consider career counseling or mentorship.")
|
32 |
+
elif data['future_insecurity'] > 5:
|
33 |
+
advice.append("Moderate future insecurity observed. Building a concrete plan and seeking guidance from trusted professionals can help.")
|
34 |
+
|
35 |
+
if data['stress_relief_activities'] < 5:
|
36 |
+
advice.append("Low engagement in stress-relief activities. Incorporate activities like walking, meditation, or pursuing hobbies into your routine.")
|
37 |
+
|
38 |
return advice
|
39 |
|
40 |
+
# Function to fetch health articles using the GROC API
|
41 |
+
def get_health_articles(query, api_key):
|
42 |
+
api_key = "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"
|
43 |
+
url = f"https://api.groc.com/search?q={query}"
|
44 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
45 |
+
|
46 |
try:
|
47 |
+
response = requests.get(url, headers=headers)
|
48 |
+
response.raise_for_status()
|
49 |
+
data = response.json() # Assuming the API returns JSON
|
50 |
+
articles = [{"title": item["title"], "url": item["url"]} for item in data.get("results", [])]
|
51 |
+
return articles
|
52 |
+
except requests.exceptions.RequestException as e:
|
53 |
st.error(f"Error fetching articles: {e}")
|
54 |
return []
|
55 |
|
56 |
# Streamlit app layout
|
57 |
def main():
|
58 |
st.title("Student Health Advisory Assistant")
|
59 |
+
st.subheader("Analyze your well-being and get advice")
|
60 |
+
|
61 |
+
# GROC API key input
|
62 |
+
api_key = st.text_input("Enter your GROC API Key", type="password")
|
63 |
+
if not api_key:
|
64 |
+
st.warning("Please enter your GROC API Key to fetch related articles.")
|
65 |
+
return
|
66 |
|
67 |
# File upload
|
68 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
69 |
if uploaded_file:
|
70 |
df = load_data(uploaded_file)
|
71 |
+
st.write("Dataset preview:")
|
72 |
st.dataframe(df.head())
|
73 |
|
74 |
+
# User input for analysis
|
75 |
+
st.header("Input Your Details")
|
76 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
77 |
age = st.slider("Age", 18, 35, step=1)
|
78 |
depression = st.slider("Depression Level (1-10)", 1, 10)
|
79 |
anxiety = st.slider("Anxiety Level (1-10)", 1, 10)
|
|
|
81 |
future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10)
|
82 |
stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10)
|
83 |
|
84 |
+
# Data dictionary for advice
|
85 |
+
user_data = {
|
86 |
+
"gender": gender,
|
87 |
+
"age": age,
|
88 |
+
"depression": depression,
|
89 |
+
"anxiety": anxiety,
|
90 |
+
"isolation": isolation,
|
91 |
+
"future_insecurity": future_insecurity,
|
92 |
+
"stress_relief_activities": stress_relief_activities,
|
93 |
+
}
|
94 |
+
|
95 |
+
# Provide advice
|
96 |
+
if st.button("Get Detailed Advice"):
|
97 |
st.subheader("Health Advice")
|
98 |
+
advice = provide_detailed_advice(user_data)
|
99 |
+
for i, tip in enumerate(advice, 1):
|
100 |
+
st.write(f"{i}. {tip}")
|
|
|
101 |
|
102 |
+
# Fetch articles from GROC API
|
103 |
st.subheader("Related Health Articles")
|
104 |
+
query = "mental health, stress relief, social well-being"
|
105 |
+
articles = get_health_articles(query, api_key)
|
106 |
if articles:
|
107 |
for article in articles:
|
108 |
st.write(f"- [{article['title']}]({article['url']})")
|
109 |
+
else:
|
110 |
+
st.write("No articles found. Please check your API key or internet connection.")
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
main()
|