hwajjala commited on
Commit
f4b1311
β€’
1 Parent(s): db86cf2

Add model files and parse

Browse files
Files changed (2) hide show
  1. app.py +35 -2
  2. text_prompts.json +390 -0
app.py CHANGED
@@ -1,9 +1,42 @@
 
1
  import clip
2
  import torch
 
 
 
3
  import gradio as gr
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def greet(name):
6
- return "Hello " + "!!"
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="image", outputs="text", allow_flagging="manual")
 
 
 
 
 
9
  iface.launch()
 
1
+ import os
2
  import clip
3
  import torch
4
+ import logging
5
+ import json
6
+ import pickle
7
  import gradio as gr
8
 
9
+
10
+ logger = logging.getLogger("basebody")
11
+ CLIP_MODEL_NAME = "ViT-B/16"
12
+
13
+ TEXT_PROMPTS_FILE_NAME = "text_prompts.json"
14
+ LOGISTIC_REGRESSION_MODEL_FILE_NAME = "logistic_regression_l1_oct_2.pkl"
15
+
16
+
17
+ clip_model, preprocess = clip.load(CLIP_MODEL_NAME, device="cpu")
18
+
19
+ with open(
20
+ os.path.join(os.path.dirname(__file__), TEXT_PROMPTS_FILE_NAME), "r"
21
+ ) as f:
22
+ text_prompts = json.load(f)
23
+ with open(
24
+ os.path.join(
25
+ os.path.dirname(__file__), LOGISTIC_REGRESSION_MODEL_FILE_NAME
26
+ ),
27
+ "rb",
28
+ ) as f:
29
+ lr_model = pickle.load(f)
30
+
31
+
32
  def greet(name):
33
+ return "Hello " + name + "!"
34
+
35
 
36
+ iface = gr.Interface(
37
+ fn=greet,
38
+ inputs="image",
39
+ outputs="text",
40
+ allow_flagging="manual"
41
+ )
42
  iface.launch()
text_prompts.json ADDED
@@ -0,0 +1,390 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clothing": [
3
+ "is character wearing clothing",
4
+ "is character not wearing clothing"
5
+ ],
6
+ "outfit": [
7
+ "is character wearing an outfit",
8
+ "is character not wearing an outfit"
9
+ ],
10
+ "equipment": [
11
+ "is character using equipment",
12
+ "is character not using equipment"
13
+ ],
14
+ "uniform": [
15
+ "is character wearing a uniform",
16
+ "is character not wearing a uniform"
17
+ ],
18
+ "jewelry": [
19
+ "is character wearing jewelry",
20
+ "is character not wearing jewelry"
21
+ ],
22
+ "jacket": [
23
+ "is character wearing a jacket",
24
+ "is character not wearing a jacket"
25
+ ],
26
+ "cardigan": [
27
+ "is character wearing a cardigan",
28
+ "is character not wearing a cardigan"
29
+ ],
30
+ "shoes": [
31
+ "is character wearing shoes",
32
+ "is character not wearing shoes"
33
+ ],
34
+ "jeans": [
35
+ "is character wearing jeans",
36
+ "is character not wearing jeans"
37
+ ],
38
+ "french": [
39
+ "is character wearing French-style clothing",
40
+ "is character not wearing French-style clothing"
41
+ ],
42
+ "chain": [
43
+ "is character wearing a chain",
44
+ "is character not wearing a chain"
45
+ ],
46
+ "weather": [
47
+ "is character wearing weather-appropriate clothing",
48
+ "is character not wearing weather-appropriate clothing"
49
+ ],
50
+ "trousers": [
51
+ "is character wearing trousers",
52
+ "is character not wearing trousers"
53
+ ],
54
+ "shorts": [
55
+ "is character wearing shorts",
56
+ "is character not wearing shorts"
57
+ ],
58
+ "tunic": [
59
+ "is character wearing a tunic",
60
+ "is character not wearing a tunic"
61
+ ],
62
+ "gown": [
63
+ "is character wearing a gown",
64
+ "is character not wearing a gown"
65
+ ],
66
+ "shirt": [
67
+ "is character wearing a shirt",
68
+ "is character not wearing a shirt"
69
+ ],
70
+ "hoodie": [
71
+ "is character wearing a hoodie",
72
+ "is character not wearing a hoodie"
73
+ ],
74
+ "crown": [
75
+ "is character wearing a crown",
76
+ "is character not wearing a crown"
77
+ ],
78
+ "suit": [
79
+ "is character wearing a suit",
80
+ "is character not wearing a suit"
81
+ ],
82
+ "armor": [
83
+ "is character wearing armor",
84
+ "is character not wearing armor"
85
+ ],
86
+ "kimono": [
87
+ "is character wearing a kimono",
88
+ "is character not wearing a kimono"
89
+ ],
90
+ "camping": [
91
+ "is character using camping equipment",
92
+ "is character not using camping equipment"
93
+ ],
94
+ "text": [
95
+ "is character wearing clothing with letters or numbers",
96
+ "is character not wearing clothing with letters or numbers"
97
+ ],
98
+ "blouse": [
99
+ "is character wearing a blouse",
100
+ "is character not wearing a blouse"
101
+ ],
102
+ "pajamas": [
103
+ "is character wearing pajamas",
104
+ "is character not wearing pajamas"
105
+ ],
106
+ "glasses": [
107
+ "is character wearing glasses",
108
+ "is character not wearing glasses"
109
+ ],
110
+ "cashmere": [
111
+ "is character wearing cashmere",
112
+ "is character not wearing cashmere"
113
+ ],
114
+ "knight": [
115
+ "is character dressed as a knight",
116
+ "is character not dressed as a knight"
117
+ ],
118
+ "fly": [
119
+ "is character wearing flying gear",
120
+ "is character not wearing flying gear"
121
+ ],
122
+ "overalls": [
123
+ "is character wearing overalls",
124
+ "is character not wearing overalls"
125
+ ],
126
+ "boxing": [
127
+ "is character wearing boxing gloves",
128
+ "is character not wearing boxing gloves"
129
+ ],
130
+ "lipstick": [
131
+ "is character wearing lipstick",
132
+ "is character not wearing lipstick"
133
+ ],
134
+ "pants": [
135
+ "is character wearing pants",
136
+ "is character not wearing pants"
137
+ ],
138
+ "apron": [
139
+ "is character wearing an apron",
140
+ "is character not wearing an apron"
141
+ ],
142
+ "zipper": [
143
+ "is character wearing something with a zipper",
144
+ "is character not wearing something with a zipper"
145
+ ],
146
+ "fighting": [
147
+ "is character wearing fighting gear",
148
+ "is character not wearing fighting gear"
149
+ ],
150
+ "headset": [
151
+ "is character wearing a headset",
152
+ "is character not wearing a headset"
153
+ ],
154
+ "lace": [
155
+ "is character wearing lace",
156
+ "is character not wearing lace"
157
+ ],
158
+ "bowling": [
159
+ "is character wearing bowling shoes",
160
+ "is character not wearing bowling shoes"
161
+ ],
162
+ "shawl": [
163
+ "is character wearing a shawl",
164
+ "is character not wearing a shawl"
165
+ ],
166
+ "flannel": [
167
+ "is character wearing flannel",
168
+ "is character not wearing flannel"
169
+ ],
170
+ "boots": [
171
+ "is character wearing boots",
172
+ "is character not wearing boots"
173
+ ],
174
+ "helmet": [
175
+ "is character wearing a helmet",
176
+ "is character not wearing a helmet"
177
+ ],
178
+ "t-shirt": [
179
+ "is character wearing a t-shirt",
180
+ "is character not wearing a t-shirt"
181
+ ],
182
+ "sandals": [
183
+ "is character wearing sandals",
184
+ "is character not wearing sandals"
185
+ ],
186
+ "jersey": [
187
+ "is character wearing a jersey",
188
+ "is character not wearing a jersey"
189
+ ],
190
+ "fairy": [
191
+ "is character dressed as a fairy",
192
+ "is character not dressed as a fairy"
193
+ ],
194
+ "glove": [
195
+ "is character wearing gloves",
196
+ "is character not wearing gloves"
197
+ ],
198
+ "outdoors": [
199
+ "is character wearing outdoor gear",
200
+ "is character not wearing outdoor gear"
201
+ ],
202
+ "cargo": [
203
+ "is character wearing cargo pants",
204
+ "is character not wearing cargo pants"
205
+ ],
206
+ "tank top": [
207
+ "is character wearing a tank top",
208
+ "is character not wearing a tank top"
209
+ ],
210
+ "hair extensions": [
211
+ "is character wearing hair extensions",
212
+ "is character not wearing hair extensions"
213
+ ],
214
+ "scarf": [
215
+ "is character wearing a scarf",
216
+ "is character not wearing a scarf"
217
+ ],
218
+ "coat": [
219
+ "is character wearing a coat",
220
+ "is character not wearing a coat"
221
+ ],
222
+ "robe": [
223
+ "is character wearing a robe",
224
+ "is character not wearing a robe"
225
+ ],
226
+ "wizard": [
227
+ "is character dressed as a wizard",
228
+ "is character not dressed as a wizard"
229
+ ],
230
+ "backpack": [
231
+ "is character wearing a backpack",
232
+ "is character not wearing a backpack"
233
+ ],
234
+ "trenchcoat": [
235
+ "is character wearing a trenchcoat",
236
+ "is character not wearing a trenchcoat"
237
+ ],
238
+ "dress": [
239
+ "is character wearing a dress",
240
+ "is character not wearing a dress"
241
+ ],
242
+ "hat": [
243
+ "is character wearing a hat",
244
+ "is character not wearing a hat"
245
+ ],
246
+ "belt": [
247
+ "is character wearing a belt",
248
+ "is character not wearing a belt"
249
+ ],
250
+ "watch": [
251
+ "is character wearing a watch",
252
+ "is character not wearing a watch"
253
+ ],
254
+ "bag": [
255
+ "is character carrying a bag",
256
+ "is character not carrying a bag"
257
+ ],
258
+ "umbrella": [
259
+ "is character holding an umbrella",
260
+ "is character not holding an umbrella"
261
+ ],
262
+ "tattoo": [
263
+ "does character have a tattoo",
264
+ "does character not have a tattoo"
265
+ ],
266
+ "piercing": [
267
+ "does character have a piercing",
268
+ "does character not have a piercing"
269
+ ],
270
+ "bracelet": [
271
+ "is character wearing a bracelet",
272
+ "is character not wearing a bracelet"
273
+ ],
274
+ "necklace": [
275
+ "is character wearing a necklace",
276
+ "is character not wearing a necklace"
277
+ ],
278
+ "background-objects": [
279
+ "are there objects in the background",
280
+ "there are no objects in the background"
281
+ ],
282
+ "foreground-objects": [
283
+ "are there objects in the foreground",
284
+ "there are no objects in the foreground"
285
+ ],
286
+ "animals": [
287
+ "is there an animal near the character",
288
+ "there is no animal near the character"
289
+ ],
290
+ "vehicles": [
291
+ "is there a vehicle near the character",
292
+ "there is no vehicle near the character"
293
+ ],
294
+ "instruments": [
295
+ "is character holding a musical instrument",
296
+ "is character not holding a musical instrument"
297
+ ],
298
+ "weapons": [
299
+ "is character holding a weapon",
300
+ "is character not holding a weapon"
301
+ ],
302
+ "food-drink": [
303
+ "is character holding food or drink",
304
+ "is character not holding food or drink"
305
+ ],
306
+ "electronics": [
307
+ "is character using an electronic device",
308
+ "is character not using an electronic device"
309
+ ],
310
+ "books": [
311
+ "is character holding a book",
312
+ "is character not holding a book"
313
+ ],
314
+ "horns": [
315
+ "character has horns",
316
+ "character does not have horns"
317
+ ],
318
+ "skirt": [
319
+ "is character wearing a skirt",
320
+ "is character not wearing a skirt"
321
+ ],
322
+ "sweater": [
323
+ "is character wearing a sweater",
324
+ "is character not wearing a sweater"
325
+ ],
326
+ "sweatshirt": [
327
+ "is character wearing a sweatshirt",
328
+ "is character not wearing a sweatshirt"
329
+ ],
330
+ "sweatpants": [
331
+ "is character wearing sweatpants",
332
+ "is character not wearing sweatpants"
333
+ ],
334
+ "sunglasses": [
335
+ "is character wearing sunglasses",
336
+ "is character not wearing sunglasses"
337
+ ],
338
+ "tie": [
339
+ "is character wearing a tie",
340
+ "is character not wearing a tie"
341
+ ],
342
+ "skateboard": [
343
+ "is character using a skateboard",
344
+ "is character not using a skateboard"
345
+ ],
346
+ "skates": [
347
+ "is character using skates",
348
+ "is character not using skates"
349
+ ],
350
+ "rollerblades": [
351
+ "is character using rollerblades",
352
+ "is character not using rollerblades"
353
+ ],
354
+ "roller-skates": [
355
+ "is character using roller-skates",
356
+ "is character not using roller-skates"
357
+ ],
358
+ "surfboard": [
359
+ "is character using a surfboard",
360
+ "is character not using a surfboard"
361
+ ],
362
+ "snowboard": [
363
+ "is character using a snowboard",
364
+ "is character not using a snowboard"
365
+ ],
366
+ "skis": [
367
+ "is character using skis",
368
+ "is character not using skis"
369
+ ],
370
+ "goggles": [
371
+ "is character wearing goggles",
372
+ "is character not wearing goggles"
373
+ ],
374
+ "gloves": [
375
+ "is character wearing gloves",
376
+ "is character not wearing gloves"
377
+ ],
378
+ "mittens": [
379
+ "is character wearing mittens",
380
+ "is character not wearing mittens"
381
+ ],
382
+ "human": [
383
+ "is character human",
384
+ "is character not human"
385
+ ],
386
+ "animal": [
387
+ "is character an animal",
388
+ "is character not an animal"
389
+ ]
390
+ }