Pranav0111 commited on
Commit
f13b0ef
1 Parent(s): e5113bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -23
app.py CHANGED
@@ -8,32 +8,109 @@ import os
8
  # Initialize sentiment analysis pipeline
9
  sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
10
 
11
- class JournalCompanion:
12
  def __init__(self):
13
- # Initialize storage for entries (in-memory for demo)
14
- self.entries = []
15
-
16
- # Reflective prompts based on sentiment
17
  self.prompts = {
 
18
  "POSITIVE": [
19
- "What made this experience particularly meaningful?",
20
- "How can you carry this positive energy forward?",
21
- "Who would you like to share this joy with?",
22
- "What values of yours were honored in this moment?"
 
 
 
 
 
 
23
  ],
24
  "NEGATIVE": [
25
- "What could help make this situation better?",
26
- "What have you learned from this challenge?",
27
- "Who could you reach out to for support?",
28
- "What would be a small step toward improvement?"
 
 
 
 
 
 
29
  ],
30
  "NEUTRAL": [
31
- "What's on your mind right now?",
32
- "What would make today more meaningful?",
33
- "What are you looking forward to?",
34
- "What would you like to explore further?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  ]
36
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  # Affirmations based on sentiment
39
  self.affirmations = {
@@ -63,13 +140,13 @@ class JournalCompanion:
63
  return {
64
  "message": "Please write something in your journal entry.",
65
  "sentiment": "",
66
- "prompt": "",
67
  "affirmation": ""
68
  }
69
 
70
  # Perform sentiment analysis
71
  sentiment_result = sentiment_analyzer(entry_text)[0]
72
- sentiment = "POSITIVE" if sentiment_result["label"] == "POSITIVE" else "NEGATIVE"
73
 
74
  # Store entry with metadata
75
  entry_data = {
@@ -80,8 +157,10 @@ class JournalCompanion:
80
  }
81
  self.entries.append(entry_data)
82
 
83
- # Generate response
84
- prompt = random.choice(self.prompts[sentiment])
 
 
85
  affirmation = random.choice(self.affirmations[sentiment])
86
 
87
  # Calculate sentiment score percentage
@@ -92,7 +171,7 @@ class JournalCompanion:
92
  return {
93
  "message": message,
94
  "sentiment": sentiment,
95
- "prompt": prompt,
96
  "affirmation": affirmation
97
  }
98
 
@@ -134,7 +213,7 @@ def create_journal_interface():
134
  # Output components
135
  result_message = gr.Textbox(label="Analysis Result")
136
  sentiment_output = gr.Textbox(label="Detected Sentiment")
137
- prompt_output = gr.Textbox(label="Reflective Prompt")
138
  affirmation_output = gr.Textbox(label="Daily Affirmation")
139
 
140
  with gr.Row():
 
8
  # Initialize sentiment analysis pipeline
9
  sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
10
 
11
+ class JournalPrompts:
12
  def __init__(self):
 
 
 
 
13
  self.prompts = {
14
+ # Emotion-based prompts
15
  "POSITIVE": [
16
+ "What moments brought you the most joy today, and why?",
17
+ "How did you contribute to your own happiness today?",
18
+ "What accomplishment, big or small, are you proud of right now?",
19
+ "Who made a positive impact on your day? How can you pay it forward?",
20
+ "What unexpected positive surprise occurred today?",
21
+ "How did you show kindness to yourself or others today?",
22
+ "What made you laugh or smile today?",
23
+ "What personal strength helped you succeed today?",
24
+ "How did you make progress toward your goals today?",
25
+ "What are you feeling grateful for in this moment?"
26
  ],
27
  "NEGATIVE": [
28
+ "What is weighing on your mind, and what's one small step you could take to address it?",
29
+ "If you could tell someone exactly how you're feeling right now, what would you say?",
30
+ "What would make you feel even 1% better right now?",
31
+ "What lesson might be hidden in this challenging situation?",
32
+ "How have you overcome similar challenges in the past?",
33
+ "What support do you need right now, and who could provide it?",
34
+ "If your future self could send you a message of comfort, what would they say?",
35
+ "What aspects of this situation are within your control?",
36
+ "How can you show yourself compassion during this difficult time?",
37
+ "What would you tell a friend who was facing this same situation?"
38
  ],
39
  "NEUTRAL": [
40
+ "What's occupying your thoughts right now?",
41
+ "How would you describe your energy level today?",
42
+ "What would make today feel more meaningful?",
43
+ "What patterns have you noticed in your daily life lately?",
44
+ "What would you like to explore or learn more about?",
45
+ "How aligned are your actions with your values today?",
46
+ "What change would you like to see in your life six months from now?",
47
+ "What's something you've been putting off that you could tackle today?",
48
+ "How have your priorities shifted recently?",
49
+ "What boundaries do you need to set or maintain?"
50
+ ],
51
+ # Growth prompts
52
+ "GROWTH": [
53
+ "What skill would you like to develop further and why?",
54
+ "How have your beliefs or perspectives changed recently?",
55
+ "What habit would you like to build or break?",
56
+ "What's the most important lesson you've learned this week?",
57
+ "How are you different now compared to a year ago?",
58
+ "What feedback have you received recently that resonated with you?",
59
+ "What's one area of your life where you feel stuck? What's keeping you there?",
60
+ "What would you attempt if you knew you couldn't fail?",
61
+ "How do you want to be remembered?",
62
+ "What does success mean to you right now?"
63
+ ],
64
+ # Additional categories as shown in previous prompt lists...
65
+ "WELLNESS": [
66
+ "How are you taking care of your physical health today?",
67
+ "What does your body need right now?",
68
+ "How well did you sleep last night? What affected your sleep?",
69
+ "What activities make you feel most energized?",
70
+ "How do you deal with stress? What works best for you?",
71
+ "What self-care practice would be most helpful today?",
72
+ "How connected do you feel to your body right now?",
73
+ "What healthy boundary do you need to set?",
74
+ "What does balance look like in your life?",
75
+ "How do you recharge when you're feeling depleted?"
76
+ ],
77
+ "REFLECTION": [
78
+ "What patterns have you noticed in your behavior lately?",
79
+ "How have your priorities shifted in the past year?",
80
+ "What advice would you give your younger self?",
81
+ "What are you ready to let go of?",
82
+ "What beliefs about yourself are holding you back?",
83
+ "How do you handle uncertainty?",
84
+ "What role does gratitude play in your life?",
85
+ "What legacy do you want to leave?",
86
+ "How do your values guide your decisions?",
87
+ "What questions are you sitting with right now?"
88
  ]
89
  }
90
+
91
+ def get_prompt(self, category):
92
+ """Get a random prompt from the specified category"""
93
+ if category not in self.prompts:
94
+ return "Invalid category"
95
+ return random.choice(self.prompts[category])
96
+
97
+ def get_mixed_prompts(self, sentiment):
98
+ """Get a mix of prompts based on sentiment and other categories"""
99
+ prompts = []
100
+ # Add sentiment-based prompt
101
+ prompts.append(f"Emotional: {self.get_prompt(sentiment)}")
102
+ # Add growth prompt
103
+ prompts.append(f"Growth: {self.get_prompt('GROWTH')}")
104
+ # Add wellness or reflection prompt
105
+ random_category = random.choice(['WELLNESS', 'REFLECTION'])
106
+ prompts.append(f"{random_category}: {self.get_prompt(random_category)}")
107
+ return prompts
108
+
109
+ class JournalCompanion:
110
+ def __init__(self):
111
+ # Initialize storage for entries (in-memory for demo)
112
+ self.entries = []
113
+ self.journal_prompts = JournalPrompts()
114
 
115
  # Affirmations based on sentiment
116
  self.affirmations = {
 
140
  return {
141
  "message": "Please write something in your journal entry.",
142
  "sentiment": "",
143
+ "prompts": [],
144
  "affirmation": ""
145
  }
146
 
147
  # Perform sentiment analysis
148
  sentiment_result = sentiment_analyzer(entry_text)[0]
149
+ sentiment = sentiment_result["label"]
150
 
151
  # Store entry with metadata
152
  entry_data = {
 
157
  }
158
  self.entries.append(entry_data)
159
 
160
+ # Get mixed prompts based on sentiment and other categories
161
+ prompts = self.journal_prompts.get_mixed_prompts(sentiment)
162
+
163
+ # Get affirmation
164
  affirmation = random.choice(self.affirmations[sentiment])
165
 
166
  # Calculate sentiment score percentage
 
171
  return {
172
  "message": message,
173
  "sentiment": sentiment,
174
+ "prompts": "\n\n".join(prompts),
175
  "affirmation": affirmation
176
  }
177
 
 
213
  # Output components
214
  result_message = gr.Textbox(label="Analysis Result")
215
  sentiment_output = gr.Textbox(label="Detected Sentiment")
216
+ prompt_output = gr.Textbox(label="Reflective Prompts", lines=3)
217
  affirmation_output = gr.Textbox(label="Daily Affirmation")
218
 
219
  with gr.Row():