Vincent Claes commited on
Commit
6807f38
1 Parent(s): e9a8d2e

upgrade pip

Browse files
Files changed (2) hide show
  1. app.py +25 -13
  2. requirements.txt +1 -4
app.py CHANGED
@@ -27,7 +27,7 @@ def concat_images(*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:
@@ -46,14 +46,18 @@ def get_tag(emoji, tags, model=model, processor=processor, K=4):
46
  tags = tags.strip().split(",")
47
  else:
48
  tags = adjectives
49
- inputs = processor(text=tags, images=emoji, return_tensors="pt", padding=True, truncation=True)
 
 
50
  outputs = model(**inputs)
51
 
52
  # we take the softmax to get the label probabilities
53
  probs = outputs.logits_per_text.softmax(dim=0)
54
  probs_formatted = torch.tensor([prob[0] for prob in probs])
55
  values, indices = probs_formatted.topk(K)
56
- return "Tag (confidence): " + ", ".join([f"{tags[i]} ({round(v.item(), 2)})" for v, i in zip(values, indices)])
 
 
57
 
58
 
59
  title = "Tagging an Emoji"
@@ -64,13 +68,21 @@ You can also specify your own custom tags, for example; love,hate,fun,bitterness
64
 
65
  examples = [[f"emojis/{i}.png"] for i in range(32)]
66
 
67
- text = gr.inputs.Textbox(placeholder="Enter a text and we will try to predict an emoji...")
68
- gr.Interface(fn=get_tag, inputs=[gr.components.Image(type="pil", label="emoji"),
69
- gr.components.Textbox(label="tags",
70
- placeholder="Provide a comma seperated list of tags; tag1,tag2,tag3,...")],
71
- outputs=gr.Textbox(),
72
- examples=examples,
73
- examples_per_page=32,
74
- title=title,
75
- description=description,
76
- ).launch()
 
 
 
 
 
 
 
 
 
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:
 
46
  tags = tags.strip().split(",")
47
  else:
48
  tags = adjectives
49
+ inputs = processor(
50
+ text=tags, images=emoji, return_tensors="pt", padding=True, truncation=True
51
+ )
52
  outputs = model(**inputs)
53
 
54
  # we take the softmax to get the label probabilities
55
  probs = outputs.logits_per_text.softmax(dim=0)
56
  probs_formatted = torch.tensor([prob[0] for prob in probs])
57
  values, indices = probs_formatted.topk(K)
58
+ return "Tag (confidence): " + ", ".join(
59
+ [f"{tags[i]} ({round(v.item(), 2)})" for v, i in zip(values, indices)]
60
+ )
61
 
62
 
63
  title = "Tagging an Emoji"
 
68
 
69
  examples = [[f"emojis/{i}.png"] for i in range(32)]
70
 
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()
requirements.txt CHANGED
@@ -42,7 +42,7 @@ packaging==21.3
42
  pandas==1.4.4
43
  paramiko==2.11.0
44
  Pillow==9.2.0
45
- pip==22.1.2
46
  pycparser==2.21
47
  pycryptodome==3.15.0
48
  pydantic==1.10.2
@@ -73,6 +73,3 @@ uvicorn==0.18.3
73
  websockets==10.3
74
  wheel==0.37.1
75
  yarl==1.8.1
76
-
77
- [notice] A new release of pip available: 22.1.2 -> 22.2.2
78
- [notice] To update, run: pip install --upgrade pip
 
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
 
73
  websockets==10.3
74
  wheel==0.37.1
75
  yarl==1.8.1