KAZEKOI commited on
Commit
0b5fbaf
1 Parent(s): 7d02898

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +25 -6
  2. related_feature.json +0 -0
app.py CHANGED
@@ -11,6 +11,8 @@ from PIL import Image
11
  TITLE = "Tagger"
12
  DESCRIPTION = """
13
  """
 
 
14
 
15
  #HF_TOKEN = os.environ["HF_TOKEN"]
16
 
@@ -60,6 +62,7 @@ def parse_args() -> argparse.Namespace:
60
  parser.add_argument("--score-slider-step", type=float, default=0.05)
61
  parser.add_argument("--score-general-threshold", type=float, default=0.4)
62
  parser.add_argument("--score-character-threshold", type=float, default=0.9)
 
63
  parser.add_argument("--share", action="store_true")
64
  return parser.parse_args()
65
 
@@ -166,6 +169,7 @@ class Predictor:
166
  general_mcut_enabled,
167
  character_thresh,
168
  character_mcut_enabled,
 
169
  ):
170
  self.load_model(model_repo)
171
 
@@ -191,7 +195,11 @@ class Predictor:
191
  general_res = [x for x in general_names if x[1] > general_thresh]
192
  general_res = dict(general_res)
193
 
194
- with open('./implications_list.json', 'r') as f:
 
 
 
 
195
  implications_list = json.load(f)
196
 
197
  to_delete = set()
@@ -219,8 +227,17 @@ class Predictor:
219
  reverse=True,
220
  )
221
 
 
 
 
 
 
 
 
222
  sorted_general_strings = [x[0] for x in sorted_general_strings]
223
 
 
 
224
  sorted_general_strings = [x.replace("_", " ") if x not in kaomojis else x for x in sorted_general_strings]
225
 
226
  sorted_general_strings = (
@@ -284,15 +301,16 @@ def main():
284
  label="Use MCut threshold",
285
  scale=1,
286
  )
 
 
 
 
 
287
  with gr.Row():
288
  clear = gr.ClearButton(
289
  components=[
290
  image,
291
- model_repo,
292
- general_thresh,
293
- general_mcut_enabled,
294
- character_thresh,
295
- character_mcut_enabled,
296
  ],
297
  variant="secondary",
298
  size="lg",
@@ -321,6 +339,7 @@ def main():
321
  general_mcut_enabled,
322
  character_thresh,
323
  character_mcut_enabled,
 
324
  ],
325
  outputs=[sorted_general_strings, rating, character_res, general_res],
326
  )
 
11
  TITLE = "Tagger"
12
  DESCRIPTION = """
13
  """
14
+ implications_list_path = './implications_list.json'
15
+ related_feature_path = './related_feature.json'
16
 
17
  #HF_TOKEN = os.environ["HF_TOKEN"]
18
 
 
62
  parser.add_argument("--score-slider-step", type=float, default=0.05)
63
  parser.add_argument("--score-general-threshold", type=float, default=0.4)
64
  parser.add_argument("--score-character-threshold", type=float, default=0.9)
65
+ parser.add_argument("--character_string", type=str)
66
  parser.add_argument("--share", action="store_true")
67
  return parser.parse_args()
68
 
 
169
  general_mcut_enabled,
170
  character_thresh,
171
  character_mcut_enabled,
172
+ character_string,
173
  ):
174
  self.load_model(model_repo)
175
 
 
195
  general_res = [x for x in general_names if x[1] > general_thresh]
196
  general_res = dict(general_res)
197
 
198
+ with open(related_feature_path, 'r') as f:
199
+ related_feature_list = json.load(f)
200
+
201
+
202
+ with open(implications_list_path, 'r') as f:
203
  implications_list = json.load(f)
204
 
205
  to_delete = set()
 
227
  reverse=True,
228
  )
229
 
230
+ character_list = character_string.lower().split(', ')
231
+
232
+ feature_delete_list = []
233
+ for tag in character_list:
234
+ if tag in related_feature_list:
235
+ feature_delete_list.extend(related_feature_list[tag])
236
+
237
  sorted_general_strings = [x[0] for x in sorted_general_strings]
238
 
239
+ sorted_general_strings = [x for x in sorted_general_strings if x not in feature_delete_list]
240
+
241
  sorted_general_strings = [x.replace("_", " ") if x not in kaomojis else x for x in sorted_general_strings]
242
 
243
  sorted_general_strings = (
 
301
  label="Use MCut threshold",
302
  scale=1,
303
  )
304
+ with gr.Row():
305
+ character_string = gr.Textbox(
306
+ label= "Character",
307
+ scale=3,
308
+ )
309
  with gr.Row():
310
  clear = gr.ClearButton(
311
  components=[
312
  image,
313
+ character_string,
 
 
 
 
314
  ],
315
  variant="secondary",
316
  size="lg",
 
339
  general_mcut_enabled,
340
  character_thresh,
341
  character_mcut_enabled,
342
+ character_string,
343
  ],
344
  outputs=[sorted_general_strings, rating, character_res, general_res],
345
  )
related_feature.json ADDED
The diff for this file is too large to render. See raw diff