Spaces:
Sleeping
Sleeping
Sorted Captions per confidence scores
Browse files
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 |
-
|
| 16 |
-
return
|
| 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"),
|
| 33 |
-
|
|
|
|
| 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,
|