ArturoNereu commited on
Commit
f2133c2
ยท
1 Parent(s): 8f4f9ee

changed samples

Browse files
Files changed (1) hide show
  1. app.py +79 -33
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
- "dog": "๐Ÿถ",
16
- "pizza": "๐Ÿ•",
17
- "rocket": "๐Ÿš€"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("Transform your text by adding relevant emojis! This tool uses AI to understand your text and adds matching emojis to make it more expressive.")
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 is a simple Space to help build intuition around the concept of **embeddings**.
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
- For example, the word *apple* could become `[8348832, 3423943, 923493294]`. If we use the ๐ŸŽ emoji, its embedding might be `[432432, 43423, 3423423]`. When we calculate the distance between them, they're close!
 
 
59
 
60
- In this demo, we use that distance to replace words with relevant emojis. What's interesting is that it's not only about exact matchesโ€”if you write "I want ICE CREAM", you might get ๐Ÿฆ, not ๐ŸงŠ + ๐Ÿงด.
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="Enter your text",
69
- placeholder="Type something like 'I love pizza and going to the beach with my dog'",
70
- lines=3
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__":