vincentclaes vincentclaes commited on
Commit
b8821f7
·
0 Parent(s):

Duplicate from vincentclaes/emoji-tagging

Browse files

Co-authored-by: claes <vincentclaes@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Makefile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ install:
2
+ poetry install
3
+ poetry run pip list --format=freeze > requirements.txt
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Emoji Tagging
3
+ emoji: 😇
4
+ colorFrom: Blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.3.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: vincentclaes/emoji-tagging
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
15
+
16
+ # Emoji Tagging
17
+
18
+ ```bash
19
+ make setup
20
+ ```
adjectives.txt ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ adorable
2
+ adventurous
3
+ aggressive
4
+ agreeable
5
+ alert
6
+ alive
7
+ amused
8
+ angry
9
+ annoyed
10
+ annoying
11
+ anxious
12
+ arrogant
13
+ ashamed
14
+ attractive
15
+ average
16
+ awful
17
+ bad
18
+ beautiful
19
+ better
20
+ bewildered
21
+ black
22
+ bloody
23
+ blue
24
+ blue-eyed
25
+ blushing
26
+ bored
27
+ brainy
28
+ brave
29
+ breakable
30
+ bright
31
+ busy
32
+ calm
33
+ careful
34
+ cautious
35
+ charming
36
+ cheerful
37
+ clean
38
+ clear
39
+ clever
40
+ cloudy
41
+ clumsy
42
+ colorful
43
+ combative
44
+ comfortable
45
+ concerned
46
+ condemned
47
+ confused
48
+ cooperative
49
+ courageous
50
+ crazy
51
+ creepy
52
+ crowded
53
+ cruel
54
+ curious
55
+ cute
56
+ dangerous
57
+ dark
58
+ dead
59
+ defeated
60
+ defiant
61
+ delightful
62
+ depressed
63
+ determined
64
+ different
65
+ difficult
66
+ disgusted
67
+ distinct
68
+ disturbed
69
+ dizzy
70
+ doubtful
71
+ drab
72
+ dull
73
+ eager
74
+ easy
75
+ elated
76
+ elegant
77
+ embarrassed
78
+ enchanting
79
+ encouraging
80
+ energetic
81
+ enthusiastic
82
+ envious
83
+ evil
84
+ excited
85
+ expensive
86
+ exuberant
87
+ fair
88
+ faithful
89
+ famous
90
+ fancy
91
+ fantastic
92
+ fierce
93
+ filthy
94
+ fine
95
+ foolish
96
+ fragile
97
+ frail
98
+ frantic
99
+ friendly
100
+ frightened
101
+ funny
102
+ gentle
103
+ gifted
104
+ glamorous
105
+ gleaming
106
+ glorious
107
+ good
108
+ gorgeous
109
+ graceful
110
+ grieving
111
+ grotesque
112
+ grumpy
113
+ handsome
114
+ happy
115
+ healthy
116
+ helpful
117
+ helpless
118
+ hilarious
119
+ homeless
120
+ homely
121
+ horrible
122
+ hungry
123
+ hurt
124
+ ill
125
+ important
126
+ impossible
127
+ inexpensive
128
+ innocent
129
+ inquisitive
130
+ itchy
131
+ jealous
132
+ jittery
133
+ jolly
134
+ joyous
135
+ kind
136
+ lazy
137
+ light
138
+ lively
139
+ lonely
140
+ long
141
+ lovely
142
+ lucky
143
+ magnificent
144
+ misty
145
+ modern
146
+ motionless
147
+ muddy
148
+ mushy
149
+ mysterious
150
+ nasty
151
+ naughty
152
+ nervous
153
+ nice
154
+ nutty
155
+ obedient
156
+ obnoxious
157
+ odd
158
+ old-fashioned
159
+ open
160
+ outrageous
161
+ outstanding
162
+ panicky
163
+ perfect
164
+ plain
165
+ pleasant
166
+ poised
167
+ poor
168
+ powerful
169
+ precious
170
+ prickly
171
+ proud
172
+ putrid
173
+ puzzled
174
+ quaint
175
+ real
176
+ relieved
177
+ repulsive
178
+ rich
179
+ scary
180
+ selfish
181
+ shiny
182
+ shy
183
+ silly
184
+ sleepy
185
+ smiling
186
+ smoggy
187
+ sore
188
+ sparkling
189
+ splendid
190
+ spotless
191
+ stormy
192
+ strange
193
+ stupid
194
+ successful
195
+ super
196
+ talented
197
+ tame
198
+ tasty
199
+ tender
200
+ tense
201
+ terrible
202
+ thankful
203
+ thoughtful
204
+ thoughtless
205
+ tired
206
+ tough
207
+ troubled
208
+ ugliest
209
+ ugly
210
+ uninterested
211
+ unsightly
212
+ unusual
213
+ upset
214
+ uptight
215
+ vast
216
+ victorious
217
+ vivacious
218
+ wandering
219
+ weary
220
+ wicked
221
+ wide-eyed
222
+ wild
223
+ witty
224
+ worried
225
+ worrisome
226
+ wrong
227
+ zany
228
+ zealous
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import torch
4
+ import boto3
5
+
6
+ import gradio as gr
7
+ import pandas as pd
8
+
9
+ from transformers import CLIPProcessor, CLIPModel
10
+
11
+ checkpoint = "vincentclaes/emoji-predictor"
12
+ adjectives = pd.read_table("./adjectives.txt", header=None)[0].to_list()
13
+ K = 10
14
+ THRESHOLD = 0.05
15
+ APP_NAME = "emoji-tagging"
16
+ BUCKET = "drift-pilot-ml-model"
17
+
18
+ processor = CLIPProcessor.from_pretrained(checkpoint)
19
+ model = CLIPModel.from_pretrained(checkpoint)
20
+
21
+
22
+ def log_inference():
23
+ if os.environ["CLIENT"]:
24
+ boto3.client("s3").put_object(
25
+ Body=more_binary_data,
26
+ Bucket=BUCKET,
27
+ Key=f"${APP_NAME}/",
28
+ )
29
+
30
+
31
+ def get_tag(emoji, tags="", expected="", model=model, processor=processor, K=K):
32
+ if tags:
33
+ tags = tags.strip().split(",")
34
+ else:
35
+ tags = adjectives
36
+ inputs = processor(
37
+ text=tags, images=emoji, return_tensors="pt", padding=True, truncation=True
38
+ )
39
+ outputs = model(**inputs)
40
+
41
+ # we take the softmax to get the label probabilities
42
+ probs = outputs.logits_per_text.softmax(dim=0)
43
+ probs_formatted = torch.tensor([prob[0] for prob in probs])
44
+ values, indices = probs_formatted.topk(K)
45
+ return "Tag (confidence): " + ", ".join(
46
+ [f"{tags[i]} ({round(v.item(), 2)})" for v, i in zip(values, indices) if v >= THRESHOLD]
47
+ )
48
+
49
+
50
+ title = "Tagging an Emoji"
51
+ description = """You provide an Emoji and our few-shot fine tuned CLIP model will suggest some tags that are appropriate.\n
52
+
53
+ - We use the [228 most common adjectives in english](https://grammar.yourdictionary.com/parts-of-speech/adjectives/list-of-adjective-words.html).\n
54
+ - We show max 10 tags and only when the confidence is higher than 5% (0.05)
55
+
56
+ """
57
+
58
+ examples = [[f"emojis/{i}.png"] for i in range(32)]
59
+
60
+ text = gr.inputs.Textbox(
61
+ placeholder="Enter a text and we will try to predict an emoji..."
62
+ )
63
+ app = gr.Interface(
64
+ fn=get_tag,
65
+ inputs=[
66
+ gr.components.Image(type="pil", label="emoji"),
67
+ ],
68
+ outputs=gr.Textbox(),
69
+ examples=examples,
70
+ examples_per_page=32,
71
+ title=title,
72
+ description=description,
73
+ )
74
+
75
+ if __name__ == "__main__":
76
+ app.launch()
emojis/0.png ADDED
emojis/1.png ADDED
emojis/10.png ADDED
emojis/11.png ADDED
emojis/12.png ADDED
emojis/13.png ADDED
emojis/14.png ADDED
emojis/15.png ADDED
emojis/16.png ADDED
emojis/17.png ADDED
emojis/18.png ADDED
emojis/19.png ADDED
emojis/2.png ADDED
emojis/20.png ADDED
emojis/21.png ADDED
emojis/22.png ADDED
emojis/23.png ADDED
emojis/24.png ADDED
emojis/25.png ADDED
emojis/26.png ADDED
emojis/27.png ADDED
emojis/28.png ADDED
emojis/29.png ADDED
emojis/3.png ADDED
emojis/30.png ADDED
emojis/31.png ADDED
emojis/4.png ADDED
emojis/5.png ADDED
emojis/6.png ADDED
emojis/7.png ADDED
emojis/8.png ADDED
emojis/9.png ADDED
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "emoji-tagging"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Vincent Claes <vincent.v.claes@gmail.com>"]
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.10"
10
+ torch = "^1.12.1"
11
+ transformers = "^4.22.2"
12
+ gradio = "^3.4.1"
13
+ boto3 = "^1.24.89"
14
+
15
+
16
+
17
+ [tool.poetry.group.dev.dependencies]
18
+ black = "^22.10.0"
19
+
20
+ [build-system]
21
+ requires = ["poetry-core"]
22
+ build-backend = "poetry.core.masonry.api"
requirements.txt ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp==3.8.3
2
+ aiosignal==1.2.0
3
+ anyio==3.6.1
4
+ async-timeout==4.0.2
5
+ attrs==22.1.0
6
+ bcrypt==4.0.0
7
+ black==22.10.0
8
+ boto3==1.24.89
9
+ botocore==1.27.89
10
+ certifi==2022.9.24
11
+ cffi==1.15.1
12
+ charset-normalizer==2.1.1
13
+ click==8.1.3
14
+ contourpy==1.0.5
15
+ cryptography==38.0.1
16
+ cycler==0.11.0
17
+ fastapi==0.85.0
18
+ ffmpy==0.3.0
19
+ filelock==3.8.0
20
+ fonttools==4.37.4
21
+ frozenlist==1.3.1
22
+ fsspec==2022.8.2
23
+ gradio==3.4.1
24
+ h11==0.12.0
25
+ httpcore==0.15.0
26
+ httpx==0.23.0
27
+ huggingface-hub==0.10.0
28
+ idna==3.4
29
+ Jinja2==3.1.2
30
+ jmespath==1.0.1
31
+ kiwisolver==1.4.4
32
+ linkify-it-py==1.0.3
33
+ markdown-it-py==2.1.0
34
+ MarkupSafe==2.1.1
35
+ matplotlib==3.6.1
36
+ mdit-py-plugins==0.3.1
37
+ mdurl==0.1.2
38
+ multidict==6.0.2
39
+ mypy-extensions==0.4.3
40
+ numpy==1.23.3
41
+ orjson==3.8.0
42
+ packaging==21.3
43
+ pandas==1.5.0
44
+ paramiko==2.11.0
45
+ pathspec==0.10.1
46
+ Pillow==9.2.0
47
+ pip==22.0.4
48
+ platformdirs==2.5.2
49
+ pycparser==2.21
50
+ pycryptodome==3.15.0
51
+ pydantic==1.10.2
52
+ pydub==0.25.1
53
+ PyNaCl==1.5.0
54
+ pyparsing==3.0.9
55
+ python-dateutil==2.8.2
56
+ python-multipart==0.0.5
57
+ pytz==2022.4
58
+ PyYAML==6.0
59
+ regex==2022.9.13
60
+ requests==2.28.1
61
+ rfc3986==1.5.0
62
+ s3transfer==0.6.0
63
+ setuptools==65.4.1
64
+ setuptools-scm==7.0.5
65
+ six==1.16.0
66
+ sniffio==1.3.0
67
+ starlette==0.20.4
68
+ tokenizers==0.12.1
69
+ tomli==2.0.1
70
+ torch==1.12.1
71
+ tqdm==4.64.1
72
+ transformers==4.22.2
73
+ typing_extensions==4.4.0
74
+ uc-micro-py==1.0.1
75
+ urllib3==1.26.12
76
+ uvicorn==0.18.3
77
+ websockets==10.3
78
+ wheel==0.37.1
79
+ yarl==1.8.1