v2ray commited on
Commit
b32617e
·
1 Parent(s): 237d4df

Added --no-rating-prefix to convert.py.

Browse files
Files changed (2) hide show
  1. convert.py +2 -1
  2. utils/utils.py +2 -2
convert.py CHANGED
@@ -12,6 +12,7 @@ def parse_args():
12
  mutex = parser.add_mutually_exclusive_group()
13
  mutex.add_argument("-e", "--exclude", nargs="+", help="Exclude tag groups with the specified group names, you can only set either exclude or include, but not both")
14
  mutex.add_argument("-i", "--include", nargs="+", help="Include tag groups with the specified group names, you can only set either include or exclude, but not both")
 
15
  return parser.parse_args()
16
 
17
  def main():
@@ -20,7 +21,7 @@ def main():
20
  image_id_image_metadata_path_tuple_dict = utils.get_image_id_image_metadata_path_tuple_dict(IMAGE_DIR)
21
  print("Got", len(image_id_image_metadata_path_tuple_dict), "images.")
22
  for _, metadata_path in tqdm.tqdm(image_id_image_metadata_path_tuple_dict.values(), desc="Converting"):
23
- tags = utils.get_tags(metadata_path, args.exclude, args.include)
24
  random.shuffle(tags)
25
  tags_text = ", ".join(tag.replace("_", " ") for tag in tags)
26
  with open(os.path.splitext(metadata_path)[0] + ".txt", "w", encoding="utf8") as tags_file:
 
12
  mutex = parser.add_mutually_exclusive_group()
13
  mutex.add_argument("-e", "--exclude", nargs="+", help="Exclude tag groups with the specified group names, you can only set either exclude or include, but not both")
14
  mutex.add_argument("-i", "--include", nargs="+", help="Include tag groups with the specified group names, you can only set either include or exclude, but not both")
15
+ parser.add_argument("-p", "--no-rating-prefix", action="store_true", help="If set, won't prepend the \"rating:\" prefix to the rating")
16
  return parser.parse_args()
17
 
18
  def main():
 
21
  image_id_image_metadata_path_tuple_dict = utils.get_image_id_image_metadata_path_tuple_dict(IMAGE_DIR)
22
  print("Got", len(image_id_image_metadata_path_tuple_dict), "images.")
23
  for _, metadata_path in tqdm.tqdm(image_id_image_metadata_path_tuple_dict.values(), desc="Converting"):
24
+ tags = utils.get_tags(metadata_path, args.exclude, args.include, args.no_rating_prefix)
25
  random.shuffle(tags)
26
  tags_text = ", ".join(tag.replace("_", " ") for tag in tags)
27
  with open(os.path.splitext(metadata_path)[0] + ".txt", "w", encoding="utf8") as tags_file:
utils/utils.py CHANGED
@@ -90,7 +90,7 @@ def get_metadata(metadata_path):
90
  with open(metadata_path, "r", encoding="utf8") as metadata_file:
91
  return json.load(metadata_file)
92
 
93
- def get_tags(metadata_path, exclude=None, include=None):
94
  if exclude is not None and include is not None:
95
  raise ValueError("You can't set both exclude and include, please only set one.")
96
  metadata = get_metadata(metadata_path)
@@ -110,5 +110,5 @@ def get_tags(metadata_path, exclude=None, include=None):
110
  for l in type_tags_dict.values():
111
  tags += l
112
  if include_rating:
113
- tags.append("rating:" + metadata["rating"])
114
  return tags
 
90
  with open(metadata_path, "r", encoding="utf8") as metadata_file:
91
  return json.load(metadata_file)
92
 
93
+ def get_tags(metadata_path, exclude=None, include=None, no_rating_prefix=False):
94
  if exclude is not None and include is not None:
95
  raise ValueError("You can't set both exclude and include, please only set one.")
96
  metadata = get_metadata(metadata_path)
 
110
  for l in type_tags_dict.values():
111
  tags += l
112
  if include_rating:
113
+ tags.append(("" if no_rating_prefix else "rating:") + metadata["rating"])
114
  return tags