Kaushik Bar commited on
Commit
47011be
1 Parent(s): 6377947
Files changed (4) hide show
  1. app.py +33 -0
  2. examples/test1/1.jpg +0 -0
  3. examples/test1/2.JPG +0 -0
  4. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ test1_labels = "me lill;;general store;;goods;;nike;;bags;;shoe;;apparel store;;48 hours sale;;shoes;;8.8;;roadmate;;multi brand outlet;;shoe store;;find your way;;bag shop;;mall;;ralph lauren;;adidas originals;;single luxury;;flat 50%;;kailasa;;yy sports;;sale upto 50%;;laurel;;converse;;pony;;store;;kappa;;glamshops;;grocery store;;fruits;;orefici;;sale;;vans;;convienence store;;met;;yy;;grocery;;milano;;Fresh eggs;;multi brand luxury;;reebok;;bombay electric;;cloth;;manequin;;delhi electric;;lee;;caps;;zara;;crocs;;pepe jenes;;adidas;;sandals;;napa;;project x;;asics;;niche fashion;;puma;;yonex;;t-shirt;;macys;;adidas shoes;;cloth store;;le mill;;sweet monster;;shirt store;;shirt"
7
+
8
+ test2_labels = "Bata;;Tiger;;Mevious;;ministreet;;Bagong;;pepsi;;Persian Cat;;Nike;;birds;;Chesterfield;;Parcel;;Adidas;;American Express;;lions;;Ciggerete;;Puma;;xyz;;Truck;;Good food;;square one;;Courier;;Cat;;circle one;;Cignal;;Classic;;No Face masks no entry;;open;;Ciggerate;;Pall Mall;;Fortune;;Winston;;Fed Express;;Chefs Bakery;;Chefs Kitchen;;RC;;Leapard;;Dog;;JTI;;Bakery;;sophie store;;Cheetah;;mini street 27;;Hygenic;;coca cola;;Marvel;;abc;;dogs;;Malboro;;chef jhez kitchen marife patiag;;Sphynix Cat;;cats;;British American Tobacco;;BAT;;Fed Ex;;mini street convenience store albert josephparren;;Absolute;;Dunhill"
9
+
10
+ pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
11
+
12
+ def shot(image, labels_text):
13
+ PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
14
+ labels = labels_text.split(";;")
15
+ res = pipe(images=PIL_image,
16
+ candidate_labels=labels,
17
+ hypothesis_template="This is a photo of {}")
18
+ return {dic["label"]: dic["score"] for dic in res}
19
+
20
+ iface = gr.Interface(shot,
21
+ ["image", "text"],
22
+ "label",
23
+ examples=[
24
+ ["examples/test1/1.jpg", "ralph lauren;;apparel store;;ralph lauren store;;shirts;;wardrobe;;white flower"],
25
+ ["examples/test1/2.JPG", "adidas;;apparel store;;adidas store;;shirts;;wardrobe;;women training shoes;;shoes"],
26
+
27
+ #["examples/test2/1.jpg", test2_labels],
28
+ #["examples/test2/2.jpg", test2_labels],
29
+ ],
30
+ description="Add a picture and a list of labels separated by ;;",
31
+ title="Zero-shot Image Classification")
32
+
33
+ iface.launch()
examples/test1/1.jpg ADDED
examples/test1/2.JPG ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch