Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,101 +1,96 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import os
|
4 |
import requests
|
5 |
|
6 |
-
#
|
7 |
-
GROC_API_KEY = "
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
#
|
20 |
-
|
21 |
-
advice
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
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")
|
@@ -107,5 +102,5 @@ else:
|
|
107 |
else:
|
108 |
st.write("No articles found. Please check your API key or internet connection.")
|
109 |
|
110 |
-
|
111 |
-
|
|
|
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 = "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" # Replace with your actual GROC API key
|
7 |
+
|
8 |
+
# Function to load and preprocess data
|
9 |
+
@st.cache_data
|
10 |
+
def load_data(file):
|
11 |
+
df = pd.read_csv(file)
|
12 |
+
return df
|
13 |
+
|
14 |
+
# Function to provide detailed health advice based on model observation
|
15 |
+
def provide_observed_advice(data):
|
16 |
+
advice = []
|
17 |
+
|
18 |
+
# High depression, anxiety, and low stress-relief activities may indicate a need for professional help
|
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 is important to consider professional mental health support, such as therapy or counseling. Engage in calming activities like deep breathing, mindfulness, and yoga.")
|
21 |
+
|
22 |
+
# Moderate depression and anxiety levels can indicate stress but still manageable
|
23 |
+
elif data['depression'] > 5 or data['anxiety'] > 5:
|
24 |
+
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.")
|
25 |
+
|
26 |
+
# High isolation combined with low engagement in stress-relief activities could suggest loneliness
|
27 |
+
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
|
28 |
+
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.")
|
29 |
+
|
30 |
+
# If future insecurity is high, career counseling might be helpful
|
31 |
+
if data['future_insecurity'] > 7:
|
32 |
+
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.")
|
33 |
+
|
34 |
+
# Overall, low levels of stress-relief activities are a concern
|
35 |
+
if data['stress_relief_activities'] < 5:
|
36 |
+
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.")
|
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")
|
58 |
+
st.subheader("Analyze your well-being and get personalized advice")
|
59 |
+
|
60 |
+
# File upload
|
61 |
+
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
62 |
+
if uploaded_file:
|
63 |
+
df = load_data(uploaded_file)
|
64 |
+
st.write("Dataset preview:")
|
65 |
+
st.dataframe(df.head())
|
66 |
+
|
67 |
+
# User input for analysis
|
68 |
+
st.header("Input Your Details")
|
69 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
70 |
+
age = st.slider("Age", 18, 35, step=1)
|
71 |
+
depression = st.slider("Depression Level (1-10)", 1, 10)
|
72 |
+
anxiety = st.slider("Anxiety Level (1-10)", 1, 10)
|
73 |
+
isolation = st.slider("Isolation Level (1-10)", 1, 10)
|
74 |
+
future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10)
|
75 |
+
stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10)
|
76 |
+
|
77 |
+
# Data dictionary for advice
|
78 |
+
user_data = {
|
79 |
+
"gender": gender,
|
80 |
+
"age": age,
|
81 |
+
"depression": depression,
|
82 |
+
"anxiety": anxiety,
|
83 |
+
"isolation": isolation,
|
84 |
+
"future_insecurity": future_insecurity,
|
85 |
+
"stress_relief_activities": stress_relief_activities,
|
86 |
+
}
|
87 |
+
|
88 |
+
# Provide advice based on model observations
|
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")
|
|
|
102 |
else:
|
103 |
st.write("No articles found. Please check your API key or internet connection.")
|
104 |
|
105 |
+
if __name__ == "__main__":
|
106 |
+
main()
|