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()