k4d3 commited on
Commit
fc8f518
1 Parent(s): 4505cc5

joy: strip extra spaces and newlines

Browse files
Files changed (1) hide show
  1. joy +9 -4
joy CHANGED
@@ -728,7 +728,7 @@ def main():
728
  tasks.append((image_path, caption_file))
729
 
730
  if not tasks:
731
- logging.error('No input file found.')
732
  return
733
 
734
  # Validate random-tags usage
@@ -736,9 +736,7 @@ def main():
736
  parser.error("--random-tags can only be used when --feed-from-tags is enabled")
737
 
738
  if args.feed_from_tags is not None and args.artist_from_folder:
739
- raise ValueError(
740
- "feed-from-tags and artist-from-folder can't be used together"
741
- )
742
 
743
  if args.feed_from_tags is not None:
744
  logging.info("Loading e621 tag data")
@@ -775,6 +773,13 @@ def main():
775
 
776
  caption = joy_caption_model.generate_valid_caption(input_image, prompt)
777
 
 
 
 
 
 
 
 
778
  # Strip commas if the --dont-strip-commas flag is not set
779
  if not args.dont_strip_commas:
780
  # Existing comma stripping logic
 
728
  tasks.append((image_path, caption_file))
729
 
730
  if not tasks:
731
+ logging.error("No input file found.")
732
  return
733
 
734
  # Validate random-tags usage
 
736
  parser.error("--random-tags can only be used when --feed-from-tags is enabled")
737
 
738
  if args.feed_from_tags is not None and args.artist_from_folder:
739
+ raise ValueError("feed-from-tags and artist-from-folder can't be used together")
 
 
740
 
741
  if args.feed_from_tags is not None:
742
  logging.info("Loading e621 tag data")
 
773
 
774
  caption = joy_caption_model.generate_valid_caption(input_image, prompt)
775
 
776
+ # Replace multiple spaces with a single space
777
+ caption = " ".join(caption.split())
778
+ # Replace multiple newlines with a single newline
779
+ caption = "\n".join(
780
+ line for line in (line.strip() for line in caption.split("\n")) if line
781
+ )
782
+
783
  # Strip commas if the --dont-strip-commas flag is not set
784
  if not args.dont_strip_commas:
785
  # Existing comma stripping logic