oh and just one more thing.... 🐺
Browse files
joy
CHANGED
@@ -343,15 +343,24 @@ class JoyCaptionModel:
|
|
343 |
) -> str:
|
344 |
"""
|
345 |
Generate a valid caption, retrying if the caption contains only special
|
346 |
-
characters
|
347 |
-
|
|
|
348 |
"""
|
349 |
while True:
|
350 |
caption = self.process_image(
|
351 |
input_image, caption_type, caption_tone,
|
352 |
caption_length, custom_prompt
|
353 |
)
|
354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
return caption
|
356 |
print("Generated caption is invalid. Retrying...")
|
357 |
|
|
|
343 |
) -> str:
|
344 |
"""
|
345 |
Generate a valid caption, retrying if the caption contains only special
|
346 |
+
characters, does not end with a period, exclamation mark, or question
|
347 |
+
mark, contains the word fluffy more than once, repeats any word longer
|
348 |
+
than 4 characters multiple times, or contains only one sentence.
|
349 |
"""
|
350 |
while True:
|
351 |
caption = self.process_image(
|
352 |
input_image, caption_type, caption_tone,
|
353 |
caption_length, custom_prompt
|
354 |
)
|
355 |
+
words = re.findall(r'\b\w{5,}\b', caption.lower())
|
356 |
+
word_counts = {word: words.count(word) for word in set(words)}
|
357 |
+
sentence_count = len(re.findall(r'[.!?]', caption))
|
358 |
+
|
359 |
+
if (re.search(r'\w', caption) and
|
360 |
+
caption[-1] in {'.', '!', '?'} and
|
361 |
+
caption.lower().count('fluffy') <= 1 and
|
362 |
+
all(count == 1 for count in word_counts.values()) and
|
363 |
+
sentence_count > 1):
|
364 |
return caption
|
365 |
print("Generated caption is invalid. Retrying...")
|
366 |
|