File size: 3,967 Bytes
b8e4214
 
 
 
 
 
 
 
 
 
49b411b
 
b8e4214
 
49b411b
 
b8e4214
49b411b
b8e4214
49b411b
 
 
 
b8e4214
49b411b
b8e4214
 
 
49b411b
 
 
 
b8e4214
49b411b
b8e4214
 
 
 
 
49b411b
 
b8e4214
 
 
 
49b411b
b8e4214
 
 
 
49b411b
a56f6f0
 
b8e4214
 
 
49b411b
b8e4214
49b411b
 
 
b8e4214
49b411b
 
 
b8e4214
49b411b
 
 
b8e4214
49b411b
b8e4214
 
 
49b411b
 
 
b8e4214
 
 
 
 
 
49b411b
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
import streamlit as st
from textblob import TextBlob
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from transformers import pipeline

# Ensure necessary NLTK data is downloaded
nltk.download('vader_lexicon')

# Sidebar Navigation
st.sidebar.title("🧠 Mental Health Analyzer")
page = st.sidebar.radio("🌟 Navigate", ["❀️ Importance of Mental Health", "🧩 ML-Based Analysis", "πŸ€– Transformer Tips"])

# Page 1: Importance of Mental Health
if page == "❀️ Importance of Mental Health":
    st.title("🌼 Why Mental Health Matters")
    st.write("""
Mental health is crucial for overall well-being. It influences how we think, feel, and act. πŸ§ πŸ’¬
Good mental health can:
- 🌟 Improve productivity and performance
- 🀝 Enhance relationships
- πŸ’ͺ Increase self-esteem and confidence
- 🧘 Help manage emotions and stress

Remember, it's okay to seek help and talk about your feelings. πŸ€—
    """)

# Page 2: ML-Based Analysis
elif page == "🧩 ML-Based Analysis":
    st.title("πŸ§ͺ Analyze Your Mental State")
    user_input = st.text_area("✍️ Share your current thoughts or feelings:")
    if st.button("πŸ” Analyze"):
        if user_input:
            st.subheader("πŸ“ˆ Analysis Results")

            # TextBlob Sentiment
            blob = TextBlob(user_input)
            polarity = blob.sentiment.polarity
            subjectivity = blob.sentiment.subjectivity
            st.write(f"**πŸ§ͺ TextBlob Polarity:** {polarity:.2f}")
            st.write(f"**πŸ”¬ TextBlob Subjectivity:** {subjectivity:.2f}")

            # VADER Sentiment
            sid = SentimentIntensityAnalyzer()
            vader_scores = sid.polarity_scores(user_input)
            st.write(f"**⚑ VADER Compound Score:** {vader_scores['compound']:.2f}")

            # Emotion Detection with Transformers
            emotion_pipe = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion", top_k=2)
            emotions = emotion_pipe(user_input)
            st.write("**🎭 Emotion Predictions:**")
            for inner_list in emotions:
             for emo in inner_list:
                st.write(f"- {emo['label']} (Score: {emo['score']:.2f})")

            # Tips based on polarity
            st.subheader("🌈 Tips to Improve Your Mood")
            if polarity < -0.2 or vader_scores['compound'] < -0.2:
                st.write("- πŸ§˜β€β™€οΈ Practice mindfulness and deep breathing exercises.")
                st.write("- πŸ‘₯ Talk to a trusted friend or family member.")
                st.write("- 🚢 Engage in light physical activity, like a short walk.")
            elif polarity > 0.2 and vader_scores['compound'] > 0.2:
                st.write("- πŸ“– Keep up with activities that make you happy.")
                st.write("- ✍️ Share your positive feelings in a gratitude journal.")
                st.write("- πŸ€— Continue connecting with supportive people.")
            else:
                st.write("- 🧩 Take breaks and reflect on your feelings.")
                st.write("- πŸ“ Try journaling or meditation to gain clarity.")
                st.write("- πŸ›Œ Maintain a balanced routine of work and rest.")
        else:
            st.warning("⚠️ Please enter some text to analyze.")

# Page 3: Transformer-Based Tips Generator
else:
    st.title("πŸ€– Get Personalized Tips")
    user_input = st.text_area("πŸ“ Describe how you're feeling or what you need tips on:")
    if st.button("πŸš€ Generate Tips"):
        if user_input:
            gen = pipeline("text-generation", model="gpt2", max_length=150)
            prompt = f"As a supportive mental health assistant, provide tips for someone feeling: {user_input}\nTips:"
            result = gen(prompt, num_return_sequences=1)[0]['generated_text']
            st.write(result.replace(prompt, "").strip())
        else:
            st.warning("⚠️ Please share your thoughts to get tips.")