CyberWaifu commited on
Commit
598cad3
·
verified ·
1 Parent(s): 9196ede

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -61,16 +61,16 @@ def tag_image(pil_image: Image.Image, output_format: str) -> str:
61
  character_tags_with_probs.sort(key=lambda x: x[1], reverse=True)
62
  general_tags_with_probs.sort(key=lambda x: x[1], reverse=True)
63
 
64
- artist_prompt_tags = [tag.replace("_", " ").replace("(", "\\(").replace(")", "\\)") for tag, prob in artist_tags_with_probs]
65
- character_prompt_tags = [tag.replace("_", " ").replace("(", "\\(").replace(")", "\\)") for tag, prob in character_tags_with_probs]
66
- general_prompt_tags = [tag.replace("_", " ").replace("(", "\\(").replace(")", "\\)") for tag, prob in general_tags_with_probs]
67
 
68
  prompt_tags = artist_prompt_tags + character_prompt_tags + general_prompt_tags
69
 
70
  # Ensure at least one artist tag if any artist tags were predicted at all, even below threshold
71
  if not artist_prompt_tags and all_artist_tags_probs:
72
  best_artist_tag, best_artist_prob = max(all_artist_tags_probs, key=lambda item: item[1])
73
- prompt_tags = [best_artist_tag.replace("_", " ").replace("(", "\\(").replace(")", "\\)")] + prompt_tags
74
 
75
 
76
  if not prompt_tags:
@@ -93,7 +93,7 @@ def tag_image(pil_image: Image.Image, output_format: str) -> str:
93
  tag_list.sort(key=lambda x: x[1], reverse=True)
94
  lines.append(f"**Category: {cat}** – {len(tag_list)} tags")
95
  for tag, prob in tag_list:
96
- tag_pretty = tag.replace("_", " ").replace("(", "\\(").replace(")", "\\)") # Escape parentheses here
97
  lines.append(f"- {tag_pretty} (Prob: {prob:.3f})")
98
  lines.append("") # blank line between categories
99
  return "\n".join(lines)
 
61
  character_tags_with_probs.sort(key=lambda x: x[1], reverse=True)
62
  general_tags_with_probs.sort(key=lambda x: x[1], reverse=True)
63
 
64
+ artist_prompt_tags = [tag.replace("_", " ").replace("(", r"\\(").replace(")", r"\\)") for tag, prob in artist_tags_with_probs]
65
+ character_prompt_tags = [tag.replace("_", " ").replace("(", r"\\(").replace(")", r"\\)") for tag, prob in character_tags_with_probs]
66
+ general_prompt_tags = [tag.replace("_", " ").replace("(", r"\\(").replace(")", r"\\)") for tag, prob in general_tags_with_probs]
67
 
68
  prompt_tags = artist_prompt_tags + character_prompt_tags + general_prompt_tags
69
 
70
  # Ensure at least one artist tag if any artist tags were predicted at all, even below threshold
71
  if not artist_prompt_tags and all_artist_tags_probs:
72
  best_artist_tag, best_artist_prob = max(all_artist_tags_probs, key=lambda item: item[1])
73
+ prompt_tags = [best_artist_tag.replace("_", " ").replace("(", r"\\(").replace(")", r"\\)")] + prompt_tags
74
 
75
 
76
  if not prompt_tags:
 
93
  tag_list.sort(key=lambda x: x[1], reverse=True)
94
  lines.append(f"**Category: {cat}** – {len(tag_list)} tags")
95
  for tag, prob in tag_list:
96
+ tag_pretty = tag.replace("_", " ").replace("(", r"\\(").replace(")", r"\\)") # Escape parentheses here with raw string
97
  lines.append(f"- {tag_pretty} (Prob: {prob:.3f})")
98
  lines.append("") # blank line between categories
99
  return "\n".join(lines)