Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pickle | |
| import pandas as pd | |
| # Background and styling | |
| st.markdown( | |
| """ | |
| <style> | |
| .stApp::before { | |
| content: ""; | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| height: 100%; | |
| width: 100%; | |
| background-image: url("https://images.unsplash.com/photo-1516574187841-cb9cc2ca948b"); | |
| background-size: cover; | |
| background-position: center; | |
| background-attachment: fixed; | |
| opacity: 0.15; | |
| z-index: -1; | |
| } | |
| .stApp { | |
| background-color: #1e1e2f; | |
| color: #ffffff; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| } | |
| h1, h2, h3, h4, h5 { | |
| color: #ffd700 !important; | |
| } | |
| .block-container { | |
| padding: 2rem; | |
| } | |
| p, li { | |
| text-align: justify; | |
| color: #e0e0e0; | |
| font-size: 16px; | |
| } | |
| .center-button { | |
| display: flex; | |
| justify-content: center; | |
| margin-top: 30px; | |
| } | |
| .stButton>button { | |
| background-color: #ff7f50; | |
| color: white; | |
| border-radius: 12px; | |
| padding: 0.5em 2em; | |
| font-size: 16px; | |
| transition: 0.3s; | |
| } | |
| .stButton>button:hover { | |
| background-color: #ff5722; | |
| font-weight: bold; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| # Title and Form | |
| st.title("π§ Mental Health Detection") | |
| st.markdown("#### Please fill in your daily activity details to get a mental wellness insight.") | |
| # Input Form | |
| with st.form("mental_health_form"): | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| Age=st.number_input("Age",min_value=10,max_value=100) | |
| work_hours = st.number_input("π Working hours per week", min_value=20, max_value=70) | |
| Family_history = st.selectbox("π¨βπ©βπ§ Family history of mental health issues?", ("Yes", "No")) | |
| sleep = st.number_input("π΄ Sleep hours per day", min_value=4, max_value=10) | |
| Diet = st.selectbox("π½οΈ Diet quality", ("Good", "Average", "Poor")) | |
| with col2: | |
| Gender = st.selectbox("Gender",['Male',"Female","Others"]) | |
| stress = st.slider("π° Stress levels (1-10)", min_value=0, max_value=10) | |
| physical_activity = st.number_input("π Physical activity (minutes/day)", min_value=0, max_value=180) | |
| social_interaction = st.slider("π£οΈ Social interaction level (1-10)", min_value=0, max_value=10) | |
| # Center the submit button | |
| st.markdown('<div class="center-button">', unsafe_allow_html=True) | |
| submitted = st.form_submit_button("π Predict") | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| df = pd.DataFrame([[Age,Gender,work_hours, Family_history, sleep, stress, | |
| physical_activity, social_interaction, Diet]], | |
| columns=['Age','Gender','Work Hours', 'Family History', 'Sleep Hours', | |
| 'Stress Level', 'Physical Activity', | |
| 'Social Interaction', 'Diet Quality']) | |
| # Model prediction | |
| if submitted: | |
| with open("encoding.pkl", 'rb') as file: | |
| encode = pickle.load(file) | |
| with open("model.pkl", "rb") as file: | |
| model = pickle.load(file) | |
| with open("pip.pkl",'rb') as file: | |
| pipe=pickle.load(file) | |
| transformed_df = pipe.transform(df) | |
| prediction = model.predict(transformed_df)[0] | |
| # Output results | |
| if prediction == 1: | |
| st.warning("β οΈ You may be at risk for mental health issues. It's recommended to take some self-care actions.") | |
| else: | |
| st.success("β You're doing well! Keep up the good habits.") | |
| # Personalized Tips | |
| st.markdown("### π‘ Personalized Tips to Boost Your Mental Health") | |
| tips = [] | |
| if Diet != "Good": | |
| tips.append("π **Eat a Nutrient-Rich Snack Daily** \nSupports brain health with omega-3s, vitamins, and minerals.") | |
| if stress > 6: | |
| tips.append("π§ **Meditate or Stretch for 15 Minutes** \nEases anxiety and improves focus.") | |
| tips.append("π¬οΈ **Practice Deep Breathing for 10 Minutes** \nLowers stress and anxiety levels.") | |
| tips.append("π° **Drink Water & Take 5-Minute Breaks** \nHydration supports mental clarity.") | |
| tips.append("π§ **Walk 30 Minutes Daily with Music** \nReduces stress and uplifts mood.") | |
| if sleep < 7: | |
| tips.append("π **Set a Consistent Sleep Schedule (7β8 Hours)** \nImproves energy and stabilizes mood.") | |
| if work_hours > 50: | |
| tips.append("π **Limit Work to 40β45 Hours Per Week** \nPrevents burnout and enhances productivity.") | |
| if social_interaction < 5: | |
| tips.append("π₯ **Spend at Least 1 Hour Socializing Daily** \nBoosts emotional well-being and reduces isolation.") | |
| for tip in tips: | |
| st.markdown(f"<p>{tip}</p>", unsafe_allow_html=True) | |