Spaces:
Sleeping
Sleeping
examples n app
Browse files- .gitattributes +1 -0
- app.py +38 -0
- examples/.DS_Store +0 -0
- examples/city.jpg +3 -0
- examples/dinning_tables.jpg +3 -0
- examples/dogs.jpg +3 -0
- examples/giraffe.jpg +3 -0
- examples/woman_standing.jpg +3 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
*.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
*.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import CLIPProcessor, CLIPModel
|
3 |
+
|
4 |
+
clip = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
|
5 |
+
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
6 |
+
|
7 |
+
def inference(input_img, captions):
|
8 |
+
captions_list = captions.split(",")
|
9 |
+
inputs = processor(text=captions_list, images=input_img, return_tensors="pt", padding=True)
|
10 |
+
outputs = clip(**inputs)
|
11 |
+
# this is the image-text similarity score
|
12 |
+
logits_per_image = outputs.logits_per_image
|
13 |
+
probs = logits_per_image.softmax(dim=1)
|
14 |
+
probabilities_percentages = ', '.join(['{:.2f}%'.format(prob.item() * 100) for prob in probs[0]])
|
15 |
+
return probabilities_percentages
|
16 |
+
|
17 |
+
title = "CLIP Inference: Application using a pretrained CLIP model"
|
18 |
+
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 "
|
19 |
+
|
20 |
+
examples = [
|
21 |
+
["examples/woman_standing.jpg","woman standing inside a house, a photo of dog, running water, cupboard, home interiors"],
|
22 |
+
["examples/city.jpg","long shot of a city, sunsetting on a urban place, river with animals"],
|
23 |
+
["examples/dinning_tables.jpg","a bunch of dinning tables, cricket ground with players, movie theater, plants with music"],
|
24 |
+
["examples/giraffe.jpg","tall giraffe standing and turning back, luxurious car on a road, a bunch of people standing"],
|
25 |
+
["examples/dogs.jpg","a couple of dogs standing, woman standing inside a house, a photo of MJ"]
|
26 |
+
]
|
27 |
+
|
28 |
+
demo = gr.Interface(
|
29 |
+
inference,
|
30 |
+
inputs = [
|
31 |
+
gr.Image(shape=(416, 416), label="Input Image"),
|
32 |
+
gr.Textbox(placeholder="List of captions")],
|
33 |
+
outputs = [gr.Textbox(label="Probability score on captions likely describing the image")],
|
34 |
+
title = title,
|
35 |
+
description = description,
|
36 |
+
examples = examples,
|
37 |
+
)
|
38 |
+
demo.launch()
|
examples/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
examples/city.jpg
ADDED
Git LFS Details
|
examples/dinning_tables.jpg
ADDED
Git LFS Details
|
examples/dogs.jpg
ADDED
Git LFS Details
|
examples/giraffe.jpg
ADDED
Git LFS Details
|
examples/woman_standing.jpg
ADDED
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
+
pillow
|
4 |
+
numpy
|
5 |
+
gradio
|
6 |
+
pytorch-lightning
|
7 |
+
transformers
|