Spaces:
Sleeping
Sleeping
File size: 5,366 Bytes
aeb7752 868289f dac5058 43471b3 5117e78 dac5058 ba32f5d 0bb182a 868289f 0bb182a 868289f dac5058 0bb182a dac5058 43471b3 dac5058 e1e605f dac5058 43471b3 dac5058 43471b3 dac5058 43471b3 dac5058 e1e605f 868289f 0bb182a 868289f 0bb182a 868289f 0bb182a 868289f 5117e78 e1e605f dac5058 e1e605f 0bb182a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
import streamlit as st
import pandas as pd
import requests
import os
# Set the GROC API Key directly in the code
GROC_API_KEY = os.getenv("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") # Make sure your API key is stored in the environment variable
# Function to load and preprocess data
@st.cache_data
def load_data(file):
df = pd.read_csv(file)
return df
# Function to provide detailed health advice based on user data
def provide_observed_advice(data):
advice = []
# High depression and anxiety with low stress-relief activities
if data['depression'] > 7 and data['anxiety'] > 7:
advice.append("You seem to be experiencing high levels of both depression and anxiety. It's important to consider professional mental health support. You might also benefit from engaging in calming activities like deep breathing, mindfulness, or yoga.")
# Moderate depression or anxiety
elif data['depression'] > 5 or data['anxiety'] > 5:
advice.append("You are showing moderate levels of depression or anxiety. It would be helpful to develop healthy coping strategies like maintaining a regular sleep schedule, engaging in physical activity, and reaching out to friends or family for support.")
# High isolation and low stress-relief activities
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
advice.append("It seems you are feeling isolated, and your engagement in stress-relief activities is low. It's important to connect with friends or join community groups. Incorporate activities that help alleviate stress, such as walking, journaling, or meditation.")
# High future insecurity
if data['future_insecurity'] > 7:
advice.append("You are feeling a significant amount of insecurity about the future. It can be helpful to break down your larger goals into smaller, manageable tasks. Seeking career counseling or mentorship could provide valuable guidance and reduce anxiety about the future.")
# Overall low engagement in stress-relief activities
if data['stress_relief_activities'] < 5:
advice.append("Your engagement in stress-relief activities is quite low. It's essential to engage in activities that reduce stress and promote mental wellness, such as hobbies, physical exercise, and relaxation techniques like deep breathing or yoga.")
return advice
# Function to fetch health articles from the GROC API based on the query
def get_health_articles(query):
url = f"https://api.groc.com/search?q={query}"
headers = {"Authorization": f"Bearer {GROC_API_KEY}"}
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # This will raise an HTTPError for bad responses
data = response.json() # Assuming the API returns JSON
if 'results' in data:
articles = [{"title": item["title"], "url": item["url"]} for item in data['results']]
else:
articles = []
return articles
except requests.exceptions.HTTPError as http_err:
st.error(f"HTTP error occurred: {http_err}")
return []
except requests.exceptions.RequestException as err:
st.error(f"Error fetching articles: {err}")
return []
# Streamlit app layout
def main():
st.title("Student Health Advisory Assistant")
st.subheader("Analyze your well-being and get personalized advice")
# File upload
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
if uploaded_file:
df = load_data(uploaded_file)
st.write("Dataset preview:")
st.dataframe(df.head())
# User input for analysis
st.header("Input Your Details")
gender = st.selectbox("Gender", ["Male", "Female"])
age = st.slider("Age", 18, 35, step=1)
depression = st.slider("Depression Level (1-10)", 1, 10)
anxiety = st.slider("Anxiety Level (1-10)", 1, 10)
isolation = st.slider("Isolation Level (1-10)", 1, 10)
future_insecurity = st.slider("Future Insecurity Level (1-10)", 1, 10)
stress_relief_activities = st.slider("Stress Relief Activities Level (1-10)", 1, 10)
# Data dictionary for advice
user_data = {
"gender": gender,
"age": age,
"depression": depression,
"anxiety": anxiety,
"isolation": isolation,
"future_insecurity": future_insecurity,
"stress_relief_activities": stress_relief_activities,
}
# Provide advice based on user inputs
if st.button("Get Observed Advice"):
st.subheader("Health Advice Based on Observations")
advice = provide_observed_advice(user_data)
for i, tip in enumerate(advice, 1):
st.write(f"{i}. {tip}")
# Fetch related health articles based on user input
st.subheader("Related Health Articles")
query = "mental health anxiety depression isolation stress relief"
articles = get_health_articles(query)
if articles:
for article in articles:
st.write(f"- [{article['title']}]({article['url']})")
else:
st.write("No articles found. Please check your API key or internet connection.")
if __name__ == "__main__":
main()
|