k4d3 commited on
Commit
e77eb40
·
1 Parent(s): f1a2ec8

more --feed-from-tags

Browse files
Files changed (1) hide show
  1. joy +14 -5
joy CHANGED
@@ -448,8 +448,10 @@ def main():
448
  )
449
  parser.add_argument(
450
  '--feed-from-tags',
451
- action='store_true',
452
- help='Use .txt files with the same base filename as the images as input to the captioner'
 
 
453
  )
454
 
455
  args = parser.parse_args()
@@ -487,11 +489,18 @@ def main():
487
  )
488
  else:
489
  # Check for --feed-from-tags
490
- if args.feed_from_tags:
491
  tag_file = find_tag_file(image_path)
492
  if tag_file:
493
  with open(tag_file, 'r', encoding='utf-8') as f:
494
- custom_prompt = f.read().strip()
 
 
 
 
 
 
 
495
  caption = joy_caption_model.process_image(
496
  input_image,
497
  "custom",
@@ -523,7 +532,7 @@ def main():
523
  if args.add_commas_to_sentence_ends:
524
  caption = re.sub(r'(\.)(\s+)([A-Z])', r'\1,\2\3', caption)
525
 
526
- print(f"Caption for {image_path}:\n{caption}\n")
527
 
528
  # Save the caption to a .caption file
529
  with open(caption_file, 'w', encoding='utf-8') as f:
 
448
  )
449
  parser.add_argument(
450
  '--feed-from-tags',
451
+ type=int,
452
+ nargs='?',
453
+ const=-1,
454
+ help='Use .txt files with the same base filename as the images as input to the captioner. Optionally specify the number of tags to use.'
455
  )
456
 
457
  args = parser.parse_args()
 
489
  )
490
  else:
491
  # Check for --feed-from-tags
492
+ if args.feed_from_tags is not None:
493
  tag_file = find_tag_file(image_path)
494
  if tag_file:
495
  with open(tag_file, 'r', encoding='utf-8') as f:
496
+ tags = f.read().strip().split(',')
497
+
498
+ if args.feed_from_tags > 0:
499
+ tags = tags[:args.feed_from_tags]
500
+
501
+ tag_string = ', '.join(tags)
502
+ custom_prompt = f"Write a descriptive caption for this image in a formal tone. Use these tags as context clues to construct your caption: {tag_string}"
503
+
504
  caption = joy_caption_model.process_image(
505
  input_image,
506
  "custom",
 
532
  if args.add_commas_to_sentence_ends:
533
  caption = re.sub(r'(\.)(\s+)([A-Z])', r'\1,\2\3', caption)
534
 
535
+ print(f"Caption for {image_path}:\n\n{caption}\n\n")
536
 
537
  # Save the caption to a .caption file
538
  with open(caption_file, 'w', encoding='utf-8') as f: