Create file.py
Browse files
file.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Install the required library if not already installed
|
2 |
+
!pip install transformers
|
3 |
+
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
# Initialize the emoji generation pipeline
|
7 |
+
emoji_generator = pipeline("text2emoji")
|
8 |
+
|
9 |
+
def translate_to_emojis(text):
|
10 |
+
"""
|
11 |
+
Translates input text into a sequence of emojis.
|
12 |
+
"""
|
13 |
+
try:
|
14 |
+
emojis = emoji_generator(text)
|
15 |
+
return " ".join(emojis)
|
16 |
+
except Exception as e:
|
17 |
+
return f"Oops! Something went wrong: {str(e)}"
|
18 |
+
|
19 |
+
# Get user input
|
20 |
+
user_text = input("Enter your text: ")
|
21 |
+
|
22 |
+
# Translate to emojis
|
23 |
+
translated_emojis = translate_to_emojis(user_text)
|
24 |
+
|
25 |
+
print("\nTranslated Emojis:")
|
26 |
+
print(translated_emojis)
|