亳州网站制作公司,网监大队让网站备案,网址关键词查询,慈溪专业做网站公司文章目录 使用通配符增加prompt多样性Fooocus的风格实现 使用通配符增加prompt多样性
prompt和negative_prompt都可以通过apply_wildcards函数来实现通配符替换#xff0c;apply_wildcards会从txt中随机找一个出来。
promptsunshine, river, trees, __artist__
task_prompt … 文章目录 使用通配符增加prompt多样性Fooocus的风格实现 使用通配符增加prompt多样性
prompt和negative_prompt都可以通过apply_wildcards函数来实现通配符替换apply_wildcards会从txt中随机找一个出来。
promptsunshine, river, trees, __artist__
task_prompt apply_wildcards(prompt, task_rng)
task_negative_prompt apply_wildcards(negative_prompt, task_rng)def apply_wildcards(wildcard_text, rng, directorywildcards_path):for _ in range(wildcards_max_bfs_depth):placeholders re.findall(r__([\w-])__, wildcard_text)if len(placeholders) 0:return wildcard_textprint(f[Wildcards] processing: {wildcard_text})for placeholder in placeholders:try:words open(os.path.join(directory, f{placeholder}.txt), encodingutf-8).read().splitlines()words [x for x in words if x ! ]assert len(words) 0wildcard_text wildcard_text.replace(f__{placeholder}__, rng.choice(words), 1)except:print(f[Wildcards] Warning: {placeholder}.txt missing or empty. fUsing {placeholder} as a normal word.)wildcard_text wildcard_text.replace(f__{placeholder}__, placeholder)print(f[Wildcards] {wildcard_text})print(f[Wildcards] BFS stack overflow. Current text: {wildcard_text})return wildcard_textFooocus的风格实现
Fooocus可选多种风格都是以更改prompt和negative_prompt来实现。
风格s传入apply_style函数中得到prompt和negative_prompt
注意空列表空列表仍旧是一个空列表非空列表加空列表等于没加空列表。
positive_basic_workloads []
negative_basic_workloads []
style_selections [Fooocus Enhance, Fooocus Sharp]
task_promptsunshine, river, trees,
for s in style_selections:p, n apply_style(s, positivetask_prompt) # 得到prompt和negative_promptpositive_basic_workloads positive_basic_workloads p negative_basic_workloads negative_basic_workloads n
apply_style函数则为
def apply_style(style, positive):p, n styles[style]return p.replace({prompt}, positive).splitlines(), n.splitlines()styles是一个全局字典目前有213个key则是有213种风格。每个key中是一个2个元素的元组即是 prompt和negative_prompt p.replace(‘{prompt}’, positive).splitlines() 用用户输入的prompt来替换风格字符串可能存在的{prompt}然后使用splitlines()方法得到字符串的list返回使用splitlines()或许有深层次考虑但我没发现。 这里就会发现很容易有多个风格产生多个negativeprompt。