909ahmed commited on
Commit
479108b
·
verified ·
1 Parent(s): 02a2188

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -8,8 +8,9 @@ model, preprocess = clip.load("ViT-B/32", device=device)
8
 
9
  def clip(image, text):
10
 
 
11
  image = preprocess(image).unsqueeze(0).to(device)
12
- text = clip.tokenize([text]).to(device)
13
 
14
  with torch.no_grad():
15
  image_features = model.encode_image(image)
@@ -18,7 +19,7 @@ def clip(image, text):
18
  logits_per_image, logits_per_text = model(image, text)
19
  probs = logits_per_image.softmax(dim=-1).cpu().numpy()
20
 
21
- return probs[0]
22
 
23
  demo = gr.Interface(fn=clip, inputs=["text", "image"], outputs="text")
24
  demo.launch()
 
8
 
9
  def clip(image, text):
10
 
11
+ text = text.split(",")
12
  image = preprocess(image).unsqueeze(0).to(device)
13
+ text = clip.tokenize(text).to(device)
14
 
15
  with torch.no_grad():
16
  image_features = model.encode_image(image)
 
19
  logits_per_image, logits_per_text = model(image, text)
20
  probs = logits_per_image.softmax(dim=-1).cpu().numpy()
21
 
22
+ return probs
23
 
24
  demo = gr.Interface(fn=clip, inputs=["text", "image"], outputs="text")
25
  demo.launch()