HemaAM commited on
Commit
72b26c2
·
1 Parent(s): c0585df

Sorted Captions per confidence scores

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -11,9 +11,9 @@ def inference(input_img, captions):
11
  outputs = model(**inputs)
12
  # this is the image-text similarity score
13
  logits_per_image = outputs.logits_per_image
14
- probs = logits_per_image.softmax(dim=1)
15
- probabilities_percentages = ', '.join(['{:.2f}%'.format(prob.item() * 100) for prob in probs[0]])
16
- return probabilities_percentages
17
 
18
  title = "CLIP Inference: Application using a pretrained CLIP model"
19
  description = "An application using Gradio interface that accepts an image and some captions, and displays a probability score with which each caption describes the image "
@@ -29,8 +29,9 @@ examples = [["example_images/12863.jpg","photo of water, a photo of pizza, photo
29
 
30
  demo = gr.Interface(
31
  inference,
32
- inputs = [gr.Image(shape=(416, 416), label="Input Image"), gr.Textbox(placeholder="Enter different captions for image, separated by comma")],
33
- outputs = [gr.Textbox(label="Probability score of captions")],
 
34
  title = title,
35
  description = description,
36
  examples = examples,
 
11
  outputs = model(**inputs)
12
  # this is the image-text similarity score
13
  logits_per_image = outputs.logits_per_image
14
+ probs = logits_per_image.softmax(dim=1).tolist()[0]
15
+ confidences = {captions_list[i][:30]: probs[i] for i in range(len(probs))}
16
+ return confidences
17
 
18
  title = "CLIP Inference: Application using a pretrained CLIP model"
19
  description = "An application using Gradio interface that accepts an image and some captions, and displays a probability score with which each caption describes the image "
 
29
 
30
  demo = gr.Interface(
31
  inference,
32
+ inputs = [gr.Image(shape=(416, 416), label="Input Image"),
33
+ gr.Textbox(placeholder="Enter different captions for image, separated by comma")],
34
+ outputs = [gr.Label()],
35
  title = title,
36
  description = description,
37
  examples = examples,