Spaces:
Sleeping
Sleeping
Pranav0111
commited on
Commit
•
0da85b2
1
Parent(s):
9f919fb
Update app.py
Browse files
app.py
CHANGED
@@ -121,25 +121,28 @@ class JournalCompanion:
|
|
121 |
]
|
122 |
}
|
123 |
|
124 |
-
|
125 |
if not entry_text.strip():
|
126 |
return {
|
127 |
"message": "Please write something in your journal entry.",
|
128 |
"sentiment": "",
|
129 |
-
"prompts":
|
130 |
"affirmation": ""
|
131 |
}
|
132 |
|
133 |
try:
|
|
|
134 |
sentiment_result = sentiment_analyzer(entry_text)[0]
|
135 |
sentiment = sentiment_result["label"].upper()
|
136 |
sentiment_score = sentiment_result["score"]
|
137 |
-
except Exception:
|
|
|
|
|
138 |
return {
|
139 |
-
"message": "An error occurred during analysis.",
|
140 |
-
"sentiment": "
|
141 |
-
"prompts": "",
|
142 |
-
"affirmation": ""
|
143 |
}
|
144 |
|
145 |
entry_data = {
|
@@ -162,6 +165,7 @@ class JournalCompanion:
|
|
162 |
"affirmation": affirmation
|
163 |
}
|
164 |
|
|
|
165 |
def get_monthly_insights(self):
|
166 |
if not self.entries:
|
167 |
return "No entries yet to analyze."
|
|
|
121 |
]
|
122 |
}
|
123 |
|
124 |
+
def analyze_entry(self, entry_text):
|
125 |
if not entry_text.strip():
|
126 |
return {
|
127 |
"message": "Please write something in your journal entry.",
|
128 |
"sentiment": "",
|
129 |
+
"prompts": "",
|
130 |
"affirmation": ""
|
131 |
}
|
132 |
|
133 |
try:
|
134 |
+
# Attempt to perform sentiment analysis
|
135 |
sentiment_result = sentiment_analyzer(entry_text)[0]
|
136 |
sentiment = sentiment_result["label"].upper()
|
137 |
sentiment_score = sentiment_result["score"]
|
138 |
+
except Exception as e:
|
139 |
+
# Print the error to the console for debugging
|
140 |
+
print("Error during sentiment analysis:", e)
|
141 |
return {
|
142 |
+
"message": "An error occurred during analysis. Please try again.",
|
143 |
+
"sentiment": "Error",
|
144 |
+
"prompts": "Could not generate prompts due to an error.",
|
145 |
+
"affirmation": "Could not generate affirmation due to an error."
|
146 |
}
|
147 |
|
148 |
entry_data = {
|
|
|
165 |
"affirmation": affirmation
|
166 |
}
|
167 |
|
168 |
+
|
169 |
def get_monthly_insights(self):
|
170 |
if not self.entries:
|
171 |
return "No entries yet to analyze."
|