File size: 1,089 Bytes
01c5f66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import emoji
from transformers import Tool

class EmojifyTextTool(Tool):
    name = "emojify_text"
    description = "Emojifies text by adding relevant emojis to enhance expressiveness."
    inputs = ["text"]
    outputs = ["emojified_text"]

    def __call__(self, text: str):
        # Define a dictionary mapping keywords to emojis
        keyword_to_emoji = {
            "happy": "πŸ˜„",
            "sad": "😒",
            "love": "❀️",
            "confused": "πŸ˜•",
            "excited": "πŸŽ‰",
            # Add more keywords and corresponding emojis as needed
        }

        # Emojify the input text based on keywords
        emojified_text = self._emojify_keywords(text, keyword_to_emoji)

        # Print the emojified text
        print(f"Emojified Text: {emojified_text}")

        return emojified_text

    def _emojify_keywords(self, text, keyword_to_emoji):
        # Replace keywords in the text with corresponding emojis
        for keyword, emoji_char in keyword_to_emoji.items():
            text = text.replace(keyword, emoji_char)
        return text