Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,11 @@ import os
|
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
-
import urllib.parse
|
6 |
|
7 |
# Fetch the News API key from the environment variable
|
8 |
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
|
9 |
|
10 |
-
# Check if the API key is available
|
11 |
if not news_api_key:
|
12 |
st.error("NEWS_API_KEY is not set. Please provide a valid API key.")
|
13 |
st.stop()
|
@@ -23,23 +22,23 @@ def provide_observed_advice(data):
|
|
23 |
advice = []
|
24 |
if data['depression'] > 7 and data['anxiety'] > 7:
|
25 |
advice.append(
|
26 |
-
"You
|
27 |
)
|
28 |
if data['depression'] > 5 or data['anxiety'] > 5:
|
29 |
advice.append(
|
30 |
-
"Moderate levels of depression or anxiety detected.
|
31 |
)
|
32 |
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
|
33 |
advice.append(
|
34 |
-
"
|
35 |
)
|
36 |
if data['future_insecurity'] > 7:
|
37 |
advice.append(
|
38 |
-
"
|
39 |
)
|
40 |
if data['stress_relief_activities'] < 5:
|
41 |
advice.append(
|
42 |
-
"Low
|
43 |
)
|
44 |
return advice
|
45 |
|
@@ -60,41 +59,45 @@ def get_health_articles(query):
|
|
60 |
def main():
|
61 |
st.set_page_config(page_title="Student Health Advisory Assistant", layout="wide")
|
62 |
|
63 |
-
# Sidebar
|
64 |
with st.sidebar:
|
65 |
st.header("Navigation")
|
66 |
option = st.radio("Go to", ["Home", "Analyze Your Well-being", "Health Articles"])
|
67 |
|
68 |
-
# Home
|
69 |
if option == "Home":
|
70 |
st.title("π Welcome to the Student Health Advisory Assistant π")
|
71 |
st.image("https://via.placeholder.com/800x300?text=Student+Health+Advisory", use_column_width=True)
|
72 |
-
st.markdown(
|
|
|
|
|
73 |
st.markdown(
|
74 |
"""
|
75 |
-
|
76 |
-
-
|
77 |
-
-
|
|
|
78 |
"""
|
79 |
)
|
80 |
|
81 |
-
# Well-being
|
82 |
elif option == "Analyze Your Well-being":
|
83 |
st.title("π Analyze Your Well-being")
|
|
|
84 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
85 |
if uploaded_file:
|
86 |
df = load_data(uploaded_file)
|
87 |
st.write("### Dataset Preview:")
|
88 |
st.dataframe(df.head())
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
|
99 |
user_data = {
|
100 |
"gender": gender,
|
@@ -109,17 +112,25 @@ def main():
|
|
109 |
if st.button("Get Observed Advice"):
|
110 |
st.subheader("π Health Advice Based on Observations")
|
111 |
advice = provide_observed_advice(user_data)
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
-
# Health
|
116 |
elif option == "Health Articles":
|
117 |
st.title("π° Browse Health Articles")
|
118 |
-
|
119 |
-
|
|
|
120 |
articles = get_health_articles(query)
|
121 |
-
|
122 |
-
st.write(
|
|
|
|
|
|
|
|
|
123 |
|
124 |
if __name__ == "__main__":
|
125 |
main()
|
|
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import requests
|
|
|
5 |
|
6 |
# Fetch the News API key from the environment variable
|
7 |
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
|
8 |
|
9 |
+
# Check if the API key is available
|
10 |
if not news_api_key:
|
11 |
st.error("NEWS_API_KEY is not set. Please provide a valid API key.")
|
12 |
st.stop()
|
|
|
22 |
advice = []
|
23 |
if data['depression'] > 7 and data['anxiety'] > 7:
|
24 |
advice.append(
|
25 |
+
"You are experiencing high levels of both depression and anxiety. Seek professional support and try calming activities like mindfulness or yoga."
|
26 |
)
|
27 |
if data['depression'] > 5 or data['anxiety'] > 5:
|
28 |
advice.append(
|
29 |
+
"Moderate levels of depression or anxiety detected. Regular exercise, proper sleep, and connecting with loved ones may help."
|
30 |
)
|
31 |
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
|
32 |
advice.append(
|
33 |
+
"You may feel isolated and have low engagement in stress-relief activities. Connecting with community groups or engaging in a hobby might help."
|
34 |
)
|
35 |
if data['future_insecurity'] > 7:
|
36 |
advice.append(
|
37 |
+
"High insecurity about the future detected. Consider breaking down your goals into smaller, manageable tasks and seeking guidance from a mentor."
|
38 |
)
|
39 |
if data['stress_relief_activities'] < 5:
|
40 |
advice.append(
|
41 |
+
"Low stress-relief activity levels. Try physical activities or relaxation techniques like deep breathing or journaling."
|
42 |
)
|
43 |
return advice
|
44 |
|
|
|
59 |
def main():
|
60 |
st.set_page_config(page_title="Student Health Advisory Assistant", layout="wide")
|
61 |
|
62 |
+
# Sidebar Navigation
|
63 |
with st.sidebar:
|
64 |
st.header("Navigation")
|
65 |
option = st.radio("Go to", ["Home", "Analyze Your Well-being", "Health Articles"])
|
66 |
|
67 |
+
# Home Page
|
68 |
if option == "Home":
|
69 |
st.title("π Welcome to the Student Health Advisory Assistant π")
|
70 |
st.image("https://via.placeholder.com/800x300?text=Student+Health+Advisory", use_column_width=True)
|
71 |
+
st.markdown(
|
72 |
+
"### Helping you analyze your well-being and provide personalized advice for a healthier mind."
|
73 |
+
)
|
74 |
st.markdown(
|
75 |
"""
|
76 |
+
**Features:**
|
77 |
+
- Analyze your mental well-being through uploaded datasets.
|
78 |
+
- Get personalized advice based on your inputs.
|
79 |
+
- Explore the latest health-related articles for guidance.
|
80 |
"""
|
81 |
)
|
82 |
|
83 |
+
# Well-being Analysis
|
84 |
elif option == "Analyze Your Well-being":
|
85 |
st.title("π Analyze Your Well-being")
|
86 |
+
|
87 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
|
88 |
if uploaded_file:
|
89 |
df = load_data(uploaded_file)
|
90 |
st.write("### Dataset Preview:")
|
91 |
st.dataframe(df.head())
|
92 |
|
93 |
+
st.markdown("### Input Your Details")
|
94 |
+
gender = st.selectbox("πΉ Gender", ["Male", "Female"])
|
95 |
+
age = st.slider("πΉ Age", 18, 35, step=1)
|
96 |
+
depression = st.slider("πΉ Depression Level (1-10)", 1, 10)
|
97 |
+
anxiety = st.slider("πΉ Anxiety Level (1-10)", 1, 10)
|
98 |
+
isolation = st.slider("πΉ Isolation Level (1-10)", 1, 10)
|
99 |
+
future_insecurity = st.slider("πΉ Future Insecurity Level (1-10)", 1, 10)
|
100 |
+
stress_relief_activities = st.slider("πΉ Stress Relief Activities Level (1-10)", 1, 10)
|
101 |
|
102 |
user_data = {
|
103 |
"gender": gender,
|
|
|
112 |
if st.button("Get Observed Advice"):
|
113 |
st.subheader("π Health Advice Based on Observations")
|
114 |
advice = provide_observed_advice(user_data)
|
115 |
+
if advice:
|
116 |
+
for i, tip in enumerate(advice, 1):
|
117 |
+
st.write(f"π **{i}.** {tip}")
|
118 |
+
else:
|
119 |
+
st.warning("No specific advice available based on your inputs.")
|
120 |
|
121 |
+
# Health Articles
|
122 |
elif option == "Health Articles":
|
123 |
st.title("π° Browse Health Articles")
|
124 |
+
st.markdown("Get the latest updates and tips on mental health and well-being.")
|
125 |
+
query = st.text_input("Search for health topics (e.g., anxiety, stress relief)", value="mental health")
|
126 |
+
if st.button("Search Articles"):
|
127 |
articles = get_health_articles(query)
|
128 |
+
if articles:
|
129 |
+
st.write("### Found Articles:")
|
130 |
+
for article in articles:
|
131 |
+
st.markdown(f"π [{article['title']}]({article['url']})")
|
132 |
+
else:
|
133 |
+
st.warning("No articles found for the given topic. Try a different query.")
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
main()
|