Spaces:
Sleeping
Sleeping
update
Browse filesHow It Works
Input: The user enters text (for example, "I'm so happy today!" or "Everything sucks.").
Analysis: The tool analyzes the emotional polarity of the text with the TextBlob library.
Output: The tool gives the user a personalized suggestion or feedback based on the emotional tone of the text.
app.py
CHANGED
|
@@ -7,16 +7,26 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from textblob import TextBlob
|
| 11 |
+
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
+
def sentiment_analysis_and_reco(text: str) -> str:
|
| 15 |
+
'''
|
| 16 |
+
Analysis the text entered by the user and makes suggestions based on their emotional state.
|
| 17 |
+
|
| 18 |
Args:
|
| 19 |
+
text: Text to be analyzed.
|
| 20 |
+
'''
|
| 21 |
+
blob = TextBlob(text)
|
| 22 |
+
polarity = blob.sentiment.polarity
|
| 23 |
+
|
| 24 |
+
if polarity > 0.2:
|
| 25 |
+
return 'Your text contains a positive feeling! 😊 Are you having a good day today? You can share this energy with others too!'
|
| 26 |
+
elif polarity < -0.2:
|
| 27 |
+
return "Your text has a negative feeling. 😔 Maybe you should take some time off or take care of yourself. Take a deep breath and show yourself some compassion."
|
| 28 |
+
else:
|
| 29 |
+
return "Your text has a neutral feeling. 🤔 Maybe you could express some deeper thoughts?"
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|