Chris4K commited on
Commit
01c5f66
β€’
1 Parent(s): 063bc73

Create emojify_text.py

Browse files
Files changed (1) hide show
  1. emojify_text.py +33 -0
emojify_text.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import emoji
2
+ from transformers import Tool
3
+
4
+ class EmojifyTextTool(Tool):
5
+ name = "emojify_text"
6
+ description = "Emojifies text by adding relevant emojis to enhance expressiveness."
7
+ inputs = ["text"]
8
+ outputs = ["emojified_text"]
9
+
10
+ def __call__(self, text: str):
11
+ # Define a dictionary mapping keywords to emojis
12
+ keyword_to_emoji = {
13
+ "happy": "πŸ˜„",
14
+ "sad": "😒",
15
+ "love": "❀️",
16
+ "confused": "πŸ˜•",
17
+ "excited": "πŸŽ‰",
18
+ # Add more keywords and corresponding emojis as needed
19
+ }
20
+
21
+ # Emojify the input text based on keywords
22
+ emojified_text = self._emojify_keywords(text, keyword_to_emoji)
23
+
24
+ # Print the emojified text
25
+ print(f"Emojified Text: {emojified_text}")
26
+
27
+ return emojified_text
28
+
29
+ def _emojify_keywords(self, text, keyword_to_emoji):
30
+ # Replace keywords in the text with corresponding emojis
31
+ for keyword, emoji_char in keyword_to_emoji.items():
32
+ text = text.replace(keyword, emoji_char)
33
+ return text