saherPervaiz commited on
Commit
0d4cbaa
Β·
verified Β·
1 Parent(s): 61d5bc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -29
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, if not show an error and stop
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 seem to be experiencing high levels of both depression and anxiety. Consider professional mental health support and calming activities like deep breathing, mindfulness, or yoga."
27
  )
28
  if data['depression'] > 5 or data['anxiety'] > 5:
29
  advice.append(
30
- "Moderate levels of depression or anxiety detected. Maintain a regular sleep schedule, engage in physical activity, and reach out for support."
31
  )
32
  if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
33
  advice.append(
34
- "Feeling isolated with low stress-relief activities. Connect with friends or community groups and try journaling or meditation."
35
  )
36
  if data['future_insecurity'] > 7:
37
  advice.append(
38
- "Significant insecurity about the future detected. Break down goals into smaller tasks, and consider career counseling or mentorship."
39
  )
40
  if data['stress_relief_activities'] < 5:
41
  advice.append(
42
- "Low engagement in stress-relief activities. Try hobbies, physical exercise, or relaxation techniques like yoga."
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 for navigation
64
  with st.sidebar:
65
  st.header("Navigation")
66
  option = st.radio("Go to", ["Home", "Analyze Your Well-being", "Health Articles"])
67
 
68
- # Home page
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("### Helping you analyze your well-being and provide personalized advice for a healthier mind.")
 
 
73
  st.markdown(
74
  """
75
- - Upload your dataset for in-depth analysis.
76
- - Input your details to receive personalized advice.
77
- - Browse the latest health-related articles.
 
78
  """
79
  )
80
 
81
- # Well-being analysis
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
- with st.expander("Enter Your Details"):
91
- gender = st.selectbox("πŸ”Ή Gender", ["Male", "Female"])
92
- age = st.slider("πŸ”Ή Age", 18, 35, step=1)
93
- depression = st.slider("πŸ”Ή Depression Level (1-10)", 1, 10)
94
- anxiety = st.slider("πŸ”Ή Anxiety Level (1-10)", 1, 10)
95
- isolation = st.slider("πŸ”Ή Isolation Level (1-10)", 1, 10)
96
- future_insecurity = st.slider("πŸ”Ή Future Insecurity Level (1-10)", 1, 10)
97
- stress_relief_activities = st.slider("πŸ”Ή Stress Relief Activities Level (1-10)", 1, 10)
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
- for i, tip in enumerate(advice, 1):
113
- st.write(f"πŸ“Œ {i}. {tip}")
 
 
 
114
 
115
- # Health articles
116
  elif option == "Health Articles":
117
  st.title("πŸ“° Browse Health Articles")
118
- query = st.text_input("Search for health topics (e.g., anxiety, stress relief)")
119
- if query and st.button("Search Articles"):
 
120
  articles = get_health_articles(query)
121
- for article in articles:
122
- st.write(f"🌐 [{article['title']}]({article['url']})")
 
 
 
 
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()