tags module¶
This module contains:
a generic tag processing class that corrects case, stores a tag list, counts tags
a function that extracts a list of tags from a CLIP prompt string
- class lib.tags.Tag_processor¶
Used to store tag indices, proper tag cases, global count of the tags.
- Variables
case_fix_dict (dict) – associates the lowercase string with properly cased ones
tag_list (list) – a list of enumerated lowercase strings
global_tag_count (int) – a count of all the tags added
- add_tags(tag_list)¶
Works like put_tags, but returns nothing
- Parameters
tag_list (list) – a list of strings with tag names (case-insensitive)
Example
>>> from lib.tags import Tag_processor >>> tp = Tag_processor() >>> tp.add_tags(['SFX', 'high detail', 'light transport sharpening'])
- get_tag_list()¶
- Returns
A list of dictionaries with “id”, “name” and “rank” attribute. ID is an integer, name is a string, a rank is a float value containing the quotient of tag count divided by the global tag count.
Example
>>> from lib.tags import Tag_processor >>> tp = Tag_processor() >>> tp.put_tags(['landscape', 'beautiful', 'neon']) [0, 1, 2] >>> tp.get_tag_list() [ {'id': 0, 'name': 'landscape', 'rank': 0.3333333333333333}, {'id': 1, 'name': 'beautiful', 'rank': 0.3333333333333333}, {'id': 2, 'name': 'neon', 'rank': 0.3333333333333333} ]
- get_tag_numbers()¶
Iterate a list of tags with their count.
- Returns
a list of tuples, containing tag names and numbers
Example
>>> from lib.tags import Tag_processor >>> tp = Tag_processor() >>> tp.put_tags(['landscape', 'beautiful', 'neon']) [0, 1, 2] >>> tp.get_tag_numbers() [('landscape', 1), ('beautiful', 1), ('neon', 1)]
- get_tag_rank(tag_id)¶
- Parameters
tag_id (int) – a tag index
- Returns
a rank of a tag, the quotient of tag count divided by the global tag count
- put_tag(tag)¶
- Parameters
tag (str) – a tag name, case-insensitive
- Returns
a tag ID
Example
>>> from lib.tags import Tag_processor >>> tp = Tag_processor() >>> tp.put_tag('VFX') 0 >>> tp.put_tag('HDR') 1 >>> tp.put_tag('DSLR') 2
- put_tags(tag_list)¶
- Parameters
tag_list (list) – a list of strings with tag names (case-insensitive)
- Returns
a list of tag IDs
Example
>>> from lib.tags import Tag_processor >>> tp = Tag_processor() >>> tp.put_tags(['SFX', 'high detail', 'light transport sharpening']) [0, 1, 2]
- lib.tags.extract_tags(prompt)¶
Extract a list of the tags from a single prompt.
- Parameters
prompt (str) – a prompt for the CLIP neural network
Example
>>> from lib.tags import extract_tags >>> extract_tags('.imagine the color clash ; HDR ; hyperrealistic ; contest winner') [ 'HDR', 'hyperrealistic', 'contest winner' ]