File size: 2,621 Bytes
aeb7752
 
 
 
e561de7
 
aeb7752
e561de7
 
 
 
 
aeb7752
 
e561de7
 
aeb7752
e561de7
aeb7752
89ea4ad
e561de7
aeb7752
 
 
 
 
 
 
e561de7
aeb7752
a8ba087
e561de7
aeb7752
a8ba087
aeb7752
e561de7
aeb7752
e561de7
a8ba087
aeb7752
a8ba087
 
aeb7752
 
e561de7
 
 
 
 
 
aeb7752
e561de7
 
 
 
aeb7752
e561de7
 
a8ba087
e561de7
a8ba087
 
aeb7752
 
 
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
import streamlit as st
import pandas as pd
import requests

# Function to analyze stress level based on various factors
def analyze_stress_level(df, anxiety_level, self_esteem, academic_performance, study_load, depression):
    filtered_df = df[
        (df['anxiety_level'] == anxiety_level) &
        (df['self_esteem'] == self_esteem) &
        (df['academic_performance'] == academic_performance) &
        (df['study_load'] == study_load) &
        (df['depression'] == depression)
    ]
    if not filtered_df.empty:
        return filtered_df.iloc[0]['stress_level']
    return "No matching data found."

# Function to fetch related health articles from GROC API
def get_health_documents_from_groc(query):
    api_key = "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"  # Replace with your actual GROC API key
    url = "https://api.groc.com/v1/search"
    params = {
        "query": query,
        "api_key": api_key,
        "type": "article"
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        return response.json().get("results", [])
    else:
        st.error(f"Error {response.status_code}: {response.text}")
        return []

# Main Streamlit app
def main():
    st.title("Student Stress Analysis and Health Advisory")

    # Upload dataset
    uploaded_file = st.file_uploader("Upload your dataset (CSV)", type="csv")
    if uploaded_file is not None:
        df = pd.read_csv(uploaded_file)
        st.write("Dataset Preview:")
        st.dataframe(df.head())

        # Input fields
        anxiety_level = st.selectbox("Anxiety Level", df['anxiety_level'].unique())
        self_esteem = st.selectbox("Self Esteem", df['self_esteem'].unique())
        academic_performance = st.selectbox("Academic Performance", df['academic_performance'].unique())
        study_load = st.selectbox("Study Load", df['study_load'].unique())
        depression = st.selectbox("Depression", df['depression'].unique())

        # Analyze stress level
        if st.button("Analyze Stress Level"):
            stress_level = analyze_stress_level(df, anxiety_level, self_esteem, academic_performance, study_load, depression)
            st.write(f"Stress Level: {stress_level}")

            # Fetch related health articles
            query = f"Stress management articles for stress level: {stress_level}"
            articles = get_health_documents_from_groc(query)
            st.write("Related Health Articles:")
            for article in articles:
                st.markdown(f"- [{article['title']}]({article['url']})")

if __name__ == "__main__":
    main()