venkyyuvy commited on
Commit
b1f02cd
·
1 Parent(s): 2e0a0d7

examples n app

Browse files
.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

  • SHA256: 940d831b736f1f0115eb618f070d1ce209968b0043f6c0f42509acf93da4191d
  • Pointer size: 132 Bytes
  • Size of remote file: 5.65 MB
examples/dinning_tables.jpg ADDED

Git LFS Details

  • SHA256: cd4125ea58d562fb72e1f92199ba13c9b640b6c12efbc4a5fe0759cb52128581
  • Pointer size: 132 Bytes
  • Size of remote file: 1.55 MB
examples/dogs.jpg ADDED

Git LFS Details

  • SHA256: b81a4c5dcda97c13e60f503065c645780c0bf306e381e4b23751803d7de861bc
  • Pointer size: 132 Bytes
  • Size of remote file: 4.17 MB
examples/giraffe.jpg ADDED

Git LFS Details

  • SHA256: 4c7a31a04df8c5f674f0f6e30a2a9a6fa5cdac073ce765441a100df248167947
  • Pointer size: 132 Bytes
  • Size of remote file: 1.52 MB
examples/woman_standing.jpg ADDED

Git LFS Details

  • SHA256: 6c45081e8ebc9100c86cfa29198687099db1eb5dbe1ed3dea253e2f4b3ec176e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.42 MB
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ pillow
4
+ numpy
5
+ gradio
6
+ pytorch-lightning
7
+ transformers