itzbhav commited on
Commit
b8e4214
·
verified ·
1 Parent(s): 36fe0bb

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +84 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ from textblob import TextBlob
4
+ import nltk
5
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
6
+ from transformers import pipeline
7
+
8
+ # Ensure necessary NLTK data is downloaded
9
+ nltk.download('vader_lexicon')
10
+
11
+ # Sidebar Navigation
12
+ st.sidebar.title("Mental Health Analyzer")
13
+ page = st.sidebar.radio("Go to", ["Importance of Mental Health", "ML-Based Analysis", "Transformer Tips"])
14
+
15
+ # Page 1: Importance of Mental Health
16
+ if page == "Importance of Mental Health":
17
+ st.title("Why Mental Health Matters")
18
+ st.write("""
19
+ Mental health is crucial for overall well-being. It influences how we think, feel, and act.
20
+ Good mental health can:
21
+ - Improve productivity and performance
22
+ - Enhance relationships
23
+ - Increase self-esteem and confidence
24
+ - Help manage emotions and stress
25
+
26
+ Remember, it's okay to seek help and talk about your feelings.
27
+ """)
28
+
29
+ # Page 2: ML-Based Analysis
30
+ elif page == "ML-Based Analysis":
31
+ st.title("Analyze Your Mental State")
32
+ user_input = st.text_area("Share your current thoughts or feelings:")
33
+ if st.button("Analyze"):
34
+ if user_input:
35
+ st.subheader("Analysis Results")
36
+
37
+ # TextBlob Sentiment
38
+ blob = TextBlob(user_input)
39
+ polarity = blob.sentiment.polarity
40
+ subjectivity = blob.sentiment.subjectivity
41
+ st.write(f"**TextBlob Polarity:** {polarity:.2f}")
42
+ st.write(f"**TextBlob Subjectivity:** {subjectivity:.2f}")
43
+
44
+ # VADER Sentiment
45
+ sid = SentimentIntensityAnalyzer()
46
+ vader_scores = sid.polarity_scores(user_input)
47
+ st.write(f"**VADER Compound Score:** {vader_scores['compound']:.2f}")
48
+
49
+ # Emotion Detection with Transformers
50
+ emotion_pipe = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion", top_k=2)
51
+ emotions = emotion_pipe(user_input)
52
+ st.write("**Emotion Predictions:**")
53
+ for emo in emotions:
54
+ st.write(f"- {emo['label']} (Score: {emo['score']:.2f})")
55
+
56
+ # Tips based on polarity
57
+ st.subheader("Tips to Improve Your Mood")
58
+ if polarity < -0.2 or vader_scores['compound'] < -0.2:
59
+ st.write("- Practice mindfulness and deep breathing exercises.")
60
+ st.write("- Talk to a trusted friend or family member.")
61
+ st.write("- Engage in light physical activity, like a short walk.")
62
+ elif polarity > 0.2 and vader_scores['compound'] > 0.2:
63
+ st.write("- Keep up with activities that make you happy.")
64
+ st.write("- Share your positive feelings in a gratitude journal.")
65
+ st.write("- Continue connecting with supportive people.")
66
+ else:
67
+ st.write("- Take breaks and reflect on your feelings.")
68
+ st.write("- Try journaling or meditation to gain clarity.")
69
+ st.write("- Maintain a balanced routine of work and rest.")
70
+ else:
71
+ st.warning("Please enter some text to analyze.")
72
+
73
+ # Page 3: Transformer-Based Tips Generator
74
+ else:
75
+ st.title("Get Personalized Tips")
76
+ user_input = st.text_area("Describe how you're feeling or what you need tips on:")
77
+ if st.button("Generate Tips"):
78
+ if user_input:
79
+ gen = pipeline("text-generation", model="gpt2", max_length=150)
80
+ prompt = f"As a supportive mental health assistant, provide tips for someone feeling: {user_input}\nTips:"
81
+ result = gen(prompt, num_return_sequences=1)[0]['generated_text']
82
+ st.write(result.replace(prompt, "").strip())
83
+ else:
84
+ st.warning("Please share your thoughts to get tips.")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+ streamlit
3
+ textblob
4
+ nltk
5
+ transformers
6
+ torch