Mubeen161 commited on
Commit
64c47f8
·
verified ·
1 Parent(s): c831977

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +139 -0
  2. requirements.txt +10 -0
main.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import streamlit as st
4
+ # st.set_option('deprecation.showPyplotGlobalUse', False)
5
+ from datetime import datetime
6
+ # import json
7
+ # import os
8
+ from textblob import TextBlob
9
+ import matplotlib.pyplot as plt
10
+ import pandas as pd
11
+ from wordcloud import WordCloud
12
+
13
+
14
+ class Journal:
15
+ def __init__(self):
16
+ self.entries = []
17
+
18
+ def add_entry(self, timestamp, entry_text):
19
+ entry = {"timestamp": timestamp, "entry_text": entry_text}
20
+ self.entries.append(entry)
21
+
22
+ def view_entries(self):
23
+ st.header("Journal Entries")
24
+ for index, entry in enumerate(self.entries, start=1):
25
+ timestamp = entry["timestamp"]
26
+ entry_text = entry["entry_text"]
27
+ st.write(f"{index}. {timestamp}\n{entry_text}\n")
28
+ st.button(f"Delete Entry {index}", key=f"delete_{index}", on_click=self.delete_entry, args=(index-1,))
29
+ st.write("------")
30
+
31
+ def delete_entry(self, index):
32
+ if 0 <= index < len(self.entries):
33
+ deleted_entry = self.entries.pop(index)
34
+ st.write("Entry deleted:")
35
+ st.write(deleted_entry)
36
+ else:
37
+ st.write("Invalid entry index.")
38
+
39
+ def sentiment_analysis(self):
40
+ positive_count = 0
41
+ negative_count = 0
42
+ neutral_count = 0
43
+
44
+ for entry in self.entries:
45
+ entry_text = entry["entry_text"]
46
+ blob = TextBlob(entry_text)
47
+ polarity = blob.sentiment.polarity
48
+
49
+ if polarity > 0.2:
50
+ positive_count += 1
51
+ elif polarity < -0.2:
52
+ negative_count += 1
53
+ else:
54
+ neutral_count += 1
55
+
56
+ return positive_count, negative_count, neutral_count
57
+
58
+ def generate_word_cloud(self):
59
+ all_text = " ".join([entry["entry_text"] for entry in self.entries])
60
+ wordcloud = WordCloud(width=800, height=400, background_color="white").generate(all_text)
61
+ plt.figure(figsize=(10, 5))
62
+ plt.imshow(wordcloud, interpolation="bilinear")
63
+ plt.axis("off")
64
+ plt.title("Word Cloud of Journal Entries")
65
+ st.pyplot()
66
+
67
+ def main():
68
+
69
+ # Center-aligned title
70
+ st.markdown(
71
+ "<div style='text-align: center;'>"
72
+ "<h1> Your Personal Mental Health Journaling Companion</h1>"
73
+ "</div>",
74
+ unsafe_allow_html=True
75
+ )
76
+
77
+ # Center-aligned and enlarged subtitle using HTML and CSS
78
+ st.markdown(
79
+ "<div style='text-align: center;'><h5 style='font-size: 25px;'>"
80
+ "Unveil Clarity Within:\n\n 'Discover Healing and Insight through Digital Journaling'"
81
+ "</h5></div>",
82
+ unsafe_allow_html=True
83
+ )
84
+
85
+ # Check and initialize journal in session state
86
+ if "journal" not in st.session_state:
87
+ st.session_state.journal = Journal()
88
+
89
+ # Center-aligned and enlarged text using HTML and CSS
90
+ st.markdown(
91
+ "<div style='text-align: left; font-size: 20px;'>"
92
+ "<i>Your thoughts are the foundation of your strength, and this digital journaling experience is designed to empower you every step of the way.</i>""</div>",
93
+ unsafe_allow_html=True
94
+ )
95
+
96
+ entry_text = st.text_area(
97
+ "**Take one step closer to healing and enter your daily journal here:**",
98
+ key="entry_text"
99
+ )
100
+
101
+
102
+ timestamp = datetime.now().strftime("%m-%d %H:%M")
103
+
104
+ if st.button("Add Entry"):
105
+ st.session_state.journal.add_entry(timestamp, entry_text)
106
+ st.success("Entry added!")
107
+
108
+ if st.button("View my Entries"):
109
+ st.session_state.journal.view_entries()
110
+ st.write("Saved Entries:")
111
+ entries_table = []
112
+ for index, entry in enumerate(st.session_state.journal.entries, start=1):
113
+ timestamp = entry["timestamp"]
114
+ entry_text = entry["entry_text"]
115
+ entries_table.append((index, timestamp, entry_text))
116
+ st.table(entries_table)
117
+
118
+ search_term = st.text_input("Search Entry:")
119
+ filtered_entries = [
120
+ (index, timestamp, entry_text)
121
+ for index, (index, timestamp, entry_text) in enumerate(entries_table, start=1)
122
+ if search_term.lower() in entry_text.lower()
123
+ ]
124
+ if search_term:
125
+ st.write("Filtered Entries:")
126
+ st.table(filtered_entries)
127
+ if st.button("Analyze my Emotions"):
128
+ positive_count, negative_count, neutral_count = st.session_state.journal.sentiment_analysis()
129
+
130
+ sentiment_df = pd.DataFrame({
131
+ 'Sentiment': ['Positive', 'Negative', 'Neutral'],
132
+ 'Count': [positive_count, negative_count, neutral_count]
133
+ })
134
+ st.bar_chart(sentiment_df.set_index('Sentiment'))
135
+ if st.button("Create a Visual Representation of my Entry"):
136
+ st.session_state.journal.generate_word_cloud()
137
+
138
+ if __name__ == '__main__':
139
+ main()
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ datetime
3
+ textblob
4
+ wordcloud==1.8.1
5
+ matplotlib
6
+ pandas
7
+ numpy
8
+ seaborn
9
+ transformers
10
+ torch