Spaces:
Sleeping
Sleeping
File size: 5,339 Bytes
8b8745e c110a72 8b8745e 0d4cbaa c110a72 8b8745e 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 8b8745e 61d5bc4 0d4cbaa 61d5bc4 8b8745e 61d5bc4 0d4cbaa 61d5bc4 8b8745e 61d5bc4 0d4cbaa 61d5bc4 8b8745e c110a72 8b8745e c110a72 8b8745e c110a72 61d5bc4 8b8745e 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 61d5bc4 879d7df 61d5bc4 879d7df 0d4cbaa 879d7df 61d5bc4 0d4cbaa 61d5bc4 0d4cbaa 8b8745e 0d4cbaa 8b8745e |
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import os
import streamlit as st
import pandas as pd
import requests
# Fetch the News API key from the environment variable
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
# Check if the API key is available
if not news_api_key:
st.error("NEWS_API_KEY is not set. Please provide a valid API key.")
st.stop()
# 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 = []
if data['depression'] > 7 and data['anxiety'] > 7:
advice.append(
"You are experiencing high levels of both depression and anxiety. Seek professional support and try calming activities like mindfulness or yoga."
)
if data['depression'] > 5 or data['anxiety'] > 5:
advice.append(
"Moderate levels of depression or anxiety detected. Regular exercise, proper sleep, and connecting with loved ones may help."
)
if data['isolation'] > 7 and data['stress_relief_activities'] < 5:
advice.append(
"You may feel isolated and have low engagement in stress-relief activities. Connecting with community groups or engaging in a hobby might help."
)
if data['future_insecurity'] > 7:
advice.append(
"High insecurity about the future detected. Consider breaking down your goals into smaller, manageable tasks and seeking guidance from a mentor."
)
if data['stress_relief_activities'] < 5:
advice.append(
"Low stress-relief activity levels. Try physical activities or relaxation techniques like deep breathing or journaling."
)
return advice
# Function to fetch health articles from News API based on the query
def get_health_articles(query):
url = f"https://newsapi.org/v2/everything?q={query}&apiKey={news_api_key}"
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
articles = [{"title": item["title"], "url": item["url"]} for item in data.get("articles", [])]
return articles
except requests.exceptions.RequestException as err:
st.error(f"Error fetching articles: {err}. Please check your internet connection.")
return []
# Streamlit app layout
def main():
st.set_page_config(page_title="Student Health Advisory Assistant", layout="wide")
# Sidebar Navigation
with st.sidebar:
st.header("Navigation")
option = st.radio("Go to", ["Home", "Analyze Your Well-being", "Health Articles"])
# Home Page
if option == "Home":
st.title("π Welcome to the Student Health Advisory Assistant π")
st.image("https://via.placeholder.com/800x300?text=Student+Health+Advisory", use_column_width=True)
st.markdown(
"### Helping you analyze your well-being and provide personalized advice for a healthier mind."
)
st.markdown(
"""
**Features:**
- Analyze your mental well-being through uploaded datasets.
- Get personalized advice based on your inputs.
- Explore the latest health-related articles for guidance.
"""
)
# Well-being Analysis
elif option == "Analyze Your Well-being":
st.title("π Analyze Your Well-being")
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())
st.markdown("### Select a Row for Analysis")
selected_row = st.selectbox(
"Select a row (based on index) to analyze:",
options=df.index,
format_func=lambda x: f"Row {x} - Age: {df.loc[x, 'age']}, Gender: {df.loc[x, 'gender']}",
)
# Extract data for the selected row
row_data = df.loc[selected_row].to_dict()
# Show extracted details
st.write("### Selected User Details:")
st.json(row_data)
# Generate advice
st.subheader("π Health Advice Based on Observations")
advice = provide_observed_advice(row_data)
if advice:
for i, tip in enumerate(advice, 1):
st.write(f"π **{i}.** {tip}")
else:
st.warning("No specific advice available based on this user's data.")
# Health Articles
elif option == "Health Articles":
st.title("π° Browse Health Articles")
st.markdown("Get the latest updates and tips on mental health and well-being.")
query = st.text_input("Search for health topics (e.g., anxiety, stress relief)", value="mental health")
if st.button("Search Articles"):
articles = get_health_articles(query)
if articles:
st.write("### Found Articles:")
for article in articles:
st.markdown(f"π [{article['title']}]({article['url']})")
else:
st.warning("No articles found for the given topic. Try a different query.")
if __name__ == "__main__":
main()
|