saherPervaiz commited on
Commit
0bb182a
·
verified ·
1 Parent(s): 228e765

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -96
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
- # Retrieve the GROC API Key from environment variable
7
- GROC_API_KEY = "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"
8
-
9
- # Check if the API key is missing
10
- if not GROC_API_KEY:
11
- st.error("API key is missing. Please set the GROC_API_KEY environment variable.")
12
- else:
13
- # Function to load and preprocess data
14
- @st.cache_data
15
- def load_data(file):
16
- df = pd.read_csv(file)
17
- return df
18
-
19
- # Function to provide detailed health advice based on model observation
20
- def provide_observed_advice(data):
21
- advice = []
22
-
23
- # High depression, anxiety, and low stress-relief activities may indicate a need for professional help
24
- if data['depression'] > 7 and data['anxiety'] > 7:
25
- 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.")
26
-
27
- # Moderate depression and anxiety levels can indicate stress but still manageable
28
- elif data['depression'] > 5 or data['anxiety'] > 5:
29
- 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.")
30
-
31
- # High isolation combined with low engagement in stress-relief activities could suggest loneliness
32
- if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
33
- 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.")
34
-
35
- # If future insecurity is high, career counseling might be helpful
36
- if data['future_insecurity'] > 7:
37
- 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.")
38
-
39
- # Overall, low levels of stress-relief activities are a concern
40
- if data['stress_relief_activities'] < 5:
41
- 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.")
42
-
43
- return advice
44
-
45
- # Function to fetch health articles from the GROC API based on the query
46
- def get_health_articles(query):
47
- url = f"https://api.groc.com/search?q={query}"
48
- headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
49
-
50
- try:
51
- response = requests.get(url, headers=headers)
52
- response.raise_for_status()
53
- data = response.json() # Assuming the API returns JSON
54
- articles = [{"title": item["title"], "url": item["url"]} for item in data.get("results", [])]
55
- return articles
56
- except requests.exceptions.RequestException as e:
57
- st.error(f"Error fetching articles: {e}")
58
- return []
59
-
60
- # Streamlit app layout
61
- def main():
62
- st.title("Student Health Advisory Assistant")
63
- st.subheader("Analyze your well-being and get personalized advice")
64
-
65
- # File upload
66
- uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
67
- if uploaded_file:
68
- df = load_data(uploaded_file)
69
- st.write("Dataset preview:")
70
- st.dataframe(df.head())
71
-
72
- # User input for analysis
73
- st.header("Input Your Details")
74
- gender = st.selectbox("Gender", ["Male", "Female"])
75
- age = st.slider("Age", 18, 35, step=1)
76
- depression = st.slider("Depression Level (1-10)", 1, 10)
77
- anxiety = st.slider("Anxiety Level (1-10)", 1, 10)
78
- isolation = st.slider("Isolation Level (1-10)", 1, 10)
79
- future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10)
80
- stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10)
81
-
82
- # Data dictionary for advice
83
- user_data = {
84
- "gender": gender,
85
- "age": age,
86
- "depression": depression,
87
- "anxiety": anxiety,
88
- "isolation": isolation,
89
- "future_insecurity": future_insecurity,
90
- "stress_relief_activities": stress_relief_activities,
91
- }
92
-
93
- # Provide advice based on model observations
94
- if st.button("Get Observed Advice"):
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
- if __name__ == "__main__":
111
- main()
 
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()