Spaces:
Sleeping
Sleeping
Commit
ยท
f2133c2
1
Parent(s):
8f4f9ee
changed samples
Browse files
app.py
CHANGED
@@ -10,13 +10,77 @@ embedder = SentenceTransformer("all-MiniLM-L6-v2")
|
|
10 |
|
11 |
# Basic emoji dictionary
|
12 |
emoji_map = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"beach": "๐๏ธ",
|
|
|
|
|
|
|
|
|
|
|
14 |
"swim": "๐",
|
15 |
-
"
|
16 |
-
"
|
17 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# Generate the embeddings on the emojis' names
|
21 |
emoji_names = list(emoji_map.keys())
|
22 |
emoji_embeddings = embedder.encode(emoji_names)
|
@@ -39,53 +103,35 @@ def translate_to_emoji(text):
|
|
39 |
|
40 |
return result
|
41 |
|
42 |
-
# UI
|
43 |
with gr.Blocks(theme="soft") as app:
|
44 |
gr.Markdown("# Emojilator ๐ฆ")
|
45 |
-
gr.Markdown("
|
46 |
|
47 |
with gr.Row():
|
48 |
with gr.Column(scale=1):
|
49 |
gr.Image("Frida_Dino.png", elem_id="mascot", show_label=False)
|
50 |
with gr.Column(scale=2):
|
51 |
-
# Embeddings explanation (full version)
|
52 |
gr.Markdown("""
|
53 |
### About this Space ๐ง
|
54 |
-
This
|
55 |
-
|
56 |
-
Most of the magic behind LLMs for developers revolves around understanding this concept: converting data into a numeric representation, or a vector.
|
57 |
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
This means we're capturing **meaning (semantics)**, not just character-to-character equality.
|
63 |
-
|
64 |
-
Check the [Space source code](https://huggingface.co/spaces/ArturoNereu/emojilator/blob/main/app.py) to learn more about the implementation.
|
65 |
""")
|
66 |
|
67 |
input_box = gr.Textbox(
|
68 |
-
label="
|
69 |
-
|
70 |
-
|
71 |
-
)
|
72 |
-
output_box = gr.Textbox(
|
73 |
-
label="Text with emojis",
|
74 |
-
lines=3
|
75 |
)
|
76 |
-
|
77 |
translate_button = gr.Button("Translate to Emoji")
|
78 |
|
79 |
-
examples = gr.Examples(
|
80 |
-
examples=[
|
81 |
-
["I love pizza and going to the beach with my dog"],
|
82 |
-
["Let's build a rocket and swim in the ocean"],
|
83 |
-
["Walking my dog to get pizza at the beach"],
|
84 |
-
["The rocket launch was amazing to watch"]
|
85 |
-
],
|
86 |
-
inputs=[input_box]
|
87 |
-
)
|
88 |
-
|
89 |
translate_button.click(translate_to_emoji, inputs=input_box, outputs=output_box)
|
90 |
|
91 |
if __name__ == "__main__":
|
|
|
10 |
|
11 |
# Basic emoji dictionary
|
12 |
emoji_map = {
|
13 |
+
# Food
|
14 |
+
"pizza": "๐",
|
15 |
+
"burger": "๐",
|
16 |
+
"fries": "๐",
|
17 |
+
"sushi": "๐ฃ",
|
18 |
+
"coffee": "โ",
|
19 |
+
"ice cream": "๐ฆ",
|
20 |
+
"cake": "๐",
|
21 |
+
"beer": "๐บ",
|
22 |
+
"wine": "๐ท",
|
23 |
+
"apple": "๐",
|
24 |
+
"banana": "๐",
|
25 |
+
"taco": "๐ฎ",
|
26 |
+
"chocolate": "๐ซ",
|
27 |
+
|
28 |
+
# Animals
|
29 |
+
"dog": "๐ถ",
|
30 |
+
"cat": "๐ฑ",
|
31 |
+
"lion": "๐ฆ",
|
32 |
+
"monkey": "๐",
|
33 |
+
"panda": "๐ผ",
|
34 |
+
"elephant": "๐",
|
35 |
+
"fish": "๐",
|
36 |
+
"bird": "๐ฆ",
|
37 |
+
"horse": "๐ด",
|
38 |
+
|
39 |
+
# Places & activities
|
40 |
"beach": "๐๏ธ",
|
41 |
+
"mountain": "โฐ๏ธ",
|
42 |
+
"city": "๐๏ธ",
|
43 |
+
"school": "๐ซ",
|
44 |
+
"work": "๐ผ",
|
45 |
+
"party": "๐",
|
46 |
"swim": "๐",
|
47 |
+
"run": "๐",
|
48 |
+
"travel": "โ๏ธ",
|
49 |
+
"camping": "๐๏ธ",
|
50 |
+
"movie": "๐ฌ",
|
51 |
+
|
52 |
+
# Objects
|
53 |
+
"rocket": "๐",
|
54 |
+
"book": "๐",
|
55 |
+
"phone": "๐ฑ",
|
56 |
+
"computer": "๐ป",
|
57 |
+
"car": "๐",
|
58 |
+
"bicycle": "๐ฒ",
|
59 |
+
"guitar": "๐ธ",
|
60 |
+
"music": "๐ต",
|
61 |
+
|
62 |
+
# Emotions
|
63 |
+
"happy": "๐",
|
64 |
+
"sad": "๐ข",
|
65 |
+
"angry": "๐ก",
|
66 |
+
"love": "โค๏ธ",
|
67 |
+
"laugh": "๐",
|
68 |
+
"sleep": "๐ด"
|
69 |
}
|
70 |
|
71 |
+
# Predefined sentences to transform
|
72 |
+
sentences = [
|
73 |
+
"I love pizza and burgers",
|
74 |
+
"My dog and cat are so cute",
|
75 |
+
"Let's go swim at the beach",
|
76 |
+
"The rocket launch was amazing",
|
77 |
+
"I am reading a good book",
|
78 |
+
"We are going camping in the mountains",
|
79 |
+
"Happy birthday! I brought cake",
|
80 |
+
"I need coffee and chocolate",
|
81 |
+
"I want to travel and see new cities"
|
82 |
+
]
|
83 |
+
|
84 |
# Generate the embeddings on the emojis' names
|
85 |
emoji_names = list(emoji_map.keys())
|
86 |
emoji_embeddings = embedder.encode(emoji_names)
|
|
|
103 |
|
104 |
return result
|
105 |
|
106 |
+
# Gradio UI
|
107 |
with gr.Blocks(theme="soft") as app:
|
108 |
gr.Markdown("# Emojilator ๐ฆ")
|
109 |
+
gr.Markdown("AI-powered emoji translator: make your text expressive with semantic emoji matching!")
|
110 |
|
111 |
with gr.Row():
|
112 |
with gr.Column(scale=1):
|
113 |
gr.Image("Frida_Dino.png", elem_id="mascot", show_label=False)
|
114 |
with gr.Column(scale=2):
|
|
|
115 |
gr.Markdown("""
|
116 |
### About this Space ๐ง
|
117 |
+
This space explains embeddings in a simple way.
|
|
|
|
|
118 |
|
119 |
+
An embedding converts words into numeric vectors that capture meaning.
|
120 |
+
For example, the word apple might be `[8348, 3423, 9234]`, while ๐ could be `[4324, 434, 3423]`.
|
121 |
+
When we calculate the distance, they're closeโso we map apple โ ๐.
|
122 |
|
123 |
+
This is why "ice cream" gives ๐ฆ instead of ๐ง + ๐งด.
|
|
|
|
|
|
|
|
|
124 |
""")
|
125 |
|
126 |
input_box = gr.Textbox(
|
127 |
+
label="Selected phrase",
|
128 |
+
lines=3,
|
129 |
+
interactive=False # makes it read-only
|
|
|
|
|
|
|
|
|
130 |
)
|
131 |
+
output_box = gr.Textbox(label="Text with emojis", lines=3)
|
132 |
translate_button = gr.Button("Translate to Emoji")
|
133 |
|
134 |
+
examples = gr.Examples(sentences, inputs=[input_box])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
translate_button.click(translate_to_emoji, inputs=input_box, outputs=output_box)
|
136 |
|
137 |
if __name__ == "__main__":
|