Vincent Claes commited on
Commit
d70f01c
1 Parent(s): b833196

update documentation

Browse files
Files changed (4) hide show
  1. app.py +28 -35
  2. poetry.lock +0 -0
  3. pyproject.toml +13 -8
  4. requirements.txt +20 -16
app.py CHANGED
@@ -1,47 +1,33 @@
1
- import gradio as gr
2
- import torch
3
  import os
4
 
5
- from PIL import Image
 
 
 
6
  import pandas as pd
7
 
8
  from transformers import CLIPProcessor, CLIPModel
9
 
10
  checkpoint = "vincentclaes/emoji-predictor"
11
- # x_, _, files = next(os.walk("./emojis"))
12
- # no_of_emojis = range(len(files))
13
- # emojis_as_images = [Image.open(f"emojis/{i}.png") for i in no_of_emojis]
14
  adjectives = pd.read_table("./adjectives.txt", header=None)[0].to_list()
15
  K = 4
 
 
16
 
17
  processor = CLIPProcessor.from_pretrained(checkpoint)
18
  model = CLIPModel.from_pretrained(checkpoint)
19
 
20
 
21
- def concat_images(*images):
22
- """Generate composite of all supplied images.
23
- https://stackoverflow.com/a/71315656/1771155
24
- """
25
- # Get the widest width.
26
- width = max(image.width for image in images)
27
- # Add up all the heights.
28
- height = max(image.height for image in images)
29
- # set the correct size of width and heigtht of composite.
30
- composite = Image.new("RGB", (2 * width, 2 * height))
31
- assert K == 4, "We expect 4 suggestions, other numbers won't work."
32
- for i, image in enumerate(images):
33
- if i == 0:
34
- composite.paste(image, (0, 0))
35
- elif i == 1:
36
- composite.paste(image, (width, 0))
37
- elif i == 2:
38
- composite.paste(image, (0, height))
39
- elif i == 3:
40
- composite.paste(image, (width, height))
41
- return composite
42
-
43
-
44
- def get_tag(emoji, tags="", model=model, processor=processor, K=4):
45
  if tags:
46
  tags = tags.strip().split(",")
47
  else:
@@ -62,8 +48,12 @@ def get_tag(emoji, tags="", model=model, processor=processor, K=4):
62
 
63
  title = "Tagging an Emoji"
64
  description = """You provide an Emoji and our few-shot fine tuned CLIP model will suggest some tags that are appropriate.\n
65
- We use the 228 most common adjectives in english](https://grammar.yourdictionary.com/parts-of-speech/adjectives/list-of-adjective-words.html).\n
66
- You can also specify your own custom tags, for example; love,hate,fun,bitterness.
 
 
 
 
67
  """
68
 
69
  examples = [[f"emojis/{i}.png"] for i in range(32)]
@@ -71,18 +61,21 @@ examples = [[f"emojis/{i}.png"] for i in range(32)]
71
  text = gr.inputs.Textbox(
72
  placeholder="Enter a text and we will try to predict an emoji..."
73
  )
74
- gr.Interface(
75
  fn=get_tag,
76
  inputs=[
77
  gr.components.Image(type="pil", label="emoji"),
78
  gr.components.Textbox(
79
  label="tags",
80
  placeholder="Provide a comma seperated list of tags; tag1,tag2,tag3,...",
81
- ),
82
  ],
83
  outputs=gr.Textbox(),
84
  examples=examples,
85
  examples_per_page=32,
86
  title=title,
87
  description=description,
88
- ).launch()
 
 
 
 
 
 
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 = 4
14
+ APP_NAME = "emoji-tagging"
15
+ BUCKET = "drift-pilot-ml-model"
16
 
17
  processor = CLIPProcessor.from_pretrained(checkpoint)
18
  model = CLIPModel.from_pretrained(checkpoint)
19
 
20
 
21
+ def log_inference():
22
+ if os.environ["CLIENT"]:
23
+ boto3.client("s3").put_object(
24
+ Body=more_binary_data,
25
+ Bucket=BUCKET,
26
+ Key=f"${APP_NAME}/",
27
+ )
28
+
29
+
30
+ def get_tag(emoji, tags="", expected="", model=model, processor=processor, K=K):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  if tags:
32
  tags = tags.strip().split(",")
33
  else:
 
48
 
49
  title = "Tagging an Emoji"
50
  description = """You provide an Emoji and our few-shot fine tuned CLIP model will suggest some tags that are appropriate.\n
51
+
52
+ - We use the [228 most common adjectives in english](https://grammar.yourdictionary.com/parts-of-speech/adjectives/list-of-adjective-words.html).\n
53
+ - You can also specify your own custom tags. try with;
54
+
55
+ love,hate,fun,bitterness,passion,dying,bliss
56
+
57
  """
58
 
59
  examples = [[f"emojis/{i}.png"] for i in range(32)]
 
61
  text = gr.inputs.Textbox(
62
  placeholder="Enter a text and we will try to predict an emoji..."
63
  )
64
+ app = gr.Interface(
65
  fn=get_tag,
66
  inputs=[
67
  gr.components.Image(type="pil", label="emoji"),
68
  gr.components.Textbox(
69
  label="tags",
70
  placeholder="Provide a comma seperated list of tags; tag1,tag2,tag3,...",
71
+ )
72
  ],
73
  outputs=gr.Textbox(),
74
  examples=examples,
75
  examples_per_page=32,
76
  title=title,
77
  description=description,
78
+ )
79
+
80
+ if __name__ == "__main__":
81
+ app.launch()
poetry.lock CHANGED
The diff for this file is too large to render. See raw diff
 
pyproject.toml CHANGED
@@ -1,18 +1,23 @@
1
  [tool.poetry]
2
- name = "emoji-predictor"
3
  version = "0.1.0"
4
  description = ""
5
- authors = ["vincent <vclaes1986@gmail.com>"]
 
 
6
 
7
  [tool.poetry.dependencies]
8
- python = "^3.9"
9
  torch = "^1.12.1"
10
- gradio = "^3.3.1"
11
- transformers = "^4.22.1"
12
- more-itertools = "^8.14.0"
13
 
14
- [tool.poetry.dev-dependencies]
 
 
 
15
 
16
  [build-system]
17
- requires = ["poetry-core>=1.0.0"]
18
  build-backend = "poetry.core.masonry.api"
 
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
+ packages = [{include = "emoji_tagging"}]
8
 
9
  [tool.poetry.dependencies]
10
+ python = "^3.10"
11
  torch = "^1.12.1"
12
+ transformers = "^4.22.2"
13
+ gradio = "^3.4.1"
14
+ boto3 = "^1.24.89"
15
 
16
+
17
+
18
+ [tool.poetry.group.dev.dependencies]
19
+ black = "^22.10.0"
20
 
21
  [build-system]
22
+ requires = ["poetry-core"]
23
  build-backend = "poetry.core.masonry.api"
requirements.txt CHANGED
@@ -1,12 +1,13 @@
1
- aiohttp==3.8.1
2
  aiosignal==1.2.0
3
- analytics-python==1.4.0
4
  anyio==3.6.1
5
  async-timeout==4.0.2
6
  attrs==22.1.0
7
- backoff==1.10.0
8
  bcrypt==4.0.0
9
- certifi==2022.9.14
 
 
 
10
  cffi==1.15.1
11
  charset-normalizer==2.1.1
12
  click==8.1.3
@@ -16,33 +17,35 @@ cycler==0.11.0
16
  fastapi==0.85.0
17
  ffmpy==0.3.0
18
  filelock==3.8.0
19
- fonttools==4.37.2
20
  frozenlist==1.3.1
21
  fsspec==2022.8.2
22
- gradio==3.3.1
23
  h11==0.12.0
24
  httpcore==0.15.0
25
  httpx==0.23.0
26
- huggingface-hub==0.9.1
27
  idna==3.4
28
  Jinja2==3.1.2
 
29
  kiwisolver==1.4.4
30
  linkify-it-py==1.0.3
31
  markdown-it-py==2.1.0
32
  MarkupSafe==2.1.1
33
- matplotlib==3.6.0
34
- mdit-py-plugins==0.3.0
35
  mdurl==0.1.2
36
- monotonic==1.6
37
- more-itertools==8.14.0
38
  multidict==6.0.2
 
39
  numpy==1.23.3
40
  orjson==3.8.0
41
  packaging==21.3
42
- pandas==1.4.4
43
  paramiko==2.11.0
 
44
  Pillow==9.2.0
45
  pip==22.2.2
 
46
  pycparser==2.21
47
  pycryptodome==3.15.0
48
  pydantic==1.10.2
@@ -51,12 +54,13 @@ PyNaCl==1.5.0
51
  pyparsing==3.0.9
52
  python-dateutil==2.8.2
53
  python-multipart==0.0.5
54
- pytz==2022.2.1
55
  PyYAML==6.0
56
  regex==2022.9.13
57
  requests==2.28.1
58
  rfc3986==1.5.0
59
- setuptools==62.6.0
 
60
  setuptools-scm==7.0.5
61
  six==1.16.0
62
  sniffio==1.3.0
@@ -65,8 +69,8 @@ tokenizers==0.12.1
65
  tomli==2.0.1
66
  torch==1.12.1
67
  tqdm==4.64.1
68
- transformers==4.22.1
69
- typing_extensions==4.3.0
70
  uc-micro-py==1.0.1
71
  urllib3==1.26.12
72
  uvicorn==0.18.3
 
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
 
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.2.2
48
+ platformdirs==2.5.2
49
  pycparser==2.21
50
  pycryptodome==3.15.0
51
  pydantic==1.10.2
 
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
 
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