Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,83 +2,70 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
|
5 |
-
# Function to
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
filtered_df = filtered_df[filtered_df[column] == value]
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return "Consider practicing relaxation techniques like yoga or meditation. Maintain healthy sleep and exercise routines."
|
22 |
-
elif stress_level == "High":
|
23 |
-
return "Seek support from counselors or health professionals. Share your concerns with trusted friends or family."
|
24 |
else:
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
def
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if response.status_code == 200:
|
38 |
-
return response.json().get("results", [])
|
39 |
-
else:
|
40 |
-
st.error(f"Error {response.status_code}: {response.text}")
|
41 |
return []
|
42 |
|
43 |
-
#
|
44 |
def main():
|
45 |
-
st.title("Student
|
46 |
|
47 |
-
#
|
48 |
-
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type="csv")
|
49 |
-
if uploaded_file
|
50 |
-
df =
|
51 |
-
st.write("Dataset Preview:")
|
52 |
st.dataframe(df.head())
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
]:
|
64 |
-
if column in df.columns:
|
65 |
-
inputs[column] = st.selectbox(f"Select {column.replace('_', ' ').title()}", df[column].unique())
|
66 |
-
|
67 |
-
# Analyze stress level
|
68 |
-
if st.button("Analyze Stress Level"):
|
69 |
-
stress_level = analyze_stress_level(df, inputs)
|
70 |
-
st.write(f"Stress Level: {stress_level}")
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
st.
|
|
|
|
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
articles
|
79 |
-
|
80 |
-
|
81 |
-
st.markdown(f"- [{article['title']}]({article['url']})")
|
82 |
|
83 |
if __name__ == "__main__":
|
84 |
main()
|
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
|
5 |
+
# Function to load and preprocess data
|
6 |
+
@st.cache_data
|
7 |
+
def load_data(file):
|
8 |
+
df = pd.read_csv(file)
|
9 |
+
return df
|
|
|
10 |
|
11 |
+
# Function to provide advice based on input
|
12 |
+
def provide_advice(gender, age, depression, anxiety, isolation, future_insecurity, stress_relief_activities):
|
13 |
+
# Analyze mental health and stress levels
|
14 |
+
if depression > 7 or anxiety > 7 or isolation > 7:
|
15 |
+
advice = "Your mental health indicators are high. Consider consulting a mental health professional for personalized support."
|
16 |
+
elif future_insecurity > 5:
|
17 |
+
advice = "Concerns about future career prospects might be contributing to your stress. Try exploring career counseling or workshops."
|
18 |
+
elif stress_relief_activities < 5:
|
19 |
+
advice = "Engage in more stress-relief activities like physical exercise, hobbies, or mindfulness practices."
|
|
|
|
|
|
|
20 |
else:
|
21 |
+
advice = "You're managing well, but continue healthy habits and seek support if needed."
|
22 |
+
return advice
|
23 |
|
24 |
+
# Mock GROC API function for fetching related articles
|
25 |
+
def get_health_articles(query):
|
26 |
+
try:
|
27 |
+
# Mock response (replace with actual GROC API call if available)
|
28 |
+
return [
|
29 |
+
{"title": "How to Manage Anxiety Effectively", "url": "https://example.com/anxiety-management"},
|
30 |
+
{"title": "Top Stress Relief Activities", "url": "https://example.com/stress-relief"}
|
31 |
+
]
|
32 |
+
except Exception as e:
|
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 section
|
47 |
+
st.header("Input Your Information")
|
48 |
+
gender = st.selectbox("Gender", df["gender"].unique())
|
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)
|
52 |
+
isolation = st.slider("Isolation Level (1-10)", 1, 10)
|
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 |
+
# Provide advice and fetch articles
|
57 |
+
if st.button("Get Advice"):
|
58 |
+
st.subheader("Health Advice")
|
59 |
+
advice = provide_advice(
|
60 |
+
gender, age, depression, anxiety, isolation, future_insecurity, stress_relief_activities
|
61 |
+
)
|
62 |
+
st.write(advice)
|
63 |
|
64 |
+
st.subheader("Related Health Articles")
|
65 |
+
articles = get_health_articles("mental health support")
|
66 |
+
if articles:
|
67 |
+
for article in articles:
|
68 |
+
st.write(f"- [{article['title']}]({article['url']})")
|
|
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
main()
|