Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add combine all description choice #2213

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions modules/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@

desc_type_photo = 'Photograph'
desc_type_anime = 'Art/Anime'
desc_type_all = 'Combine all'
50 changes: 42 additions & 8 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def ip_advance_checked(x):
with gr.Column():
desc_method = gr.Radio(
label='Content Type',
choices=[flags.desc_type_photo, flags.desc_type_anime],
choices=[flags.desc_type_photo, flags.desc_type_anime, flags.desc_type_all],
value=flags.desc_type_photo)
desc_btn = gr.Button(value='Describe this Image into Prompt')
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Document</a>')
Expand Down Expand Up @@ -592,20 +592,54 @@ def parse_meta(raw_prompt_txt, is_generating):
if os.path.exists(notification_file):
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
break

def describe_photo(img):
from extras.interrogate import default_interrogator as default_interrogator_photo
return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]

def describe_anime(img):
from extras.wd14tagger import default_interrogator as default_interrogator_anime
return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]

def merge_unique(arrays):
# Flatten the list of lists and convert to a set to remove duplicates
unique_values = set(item for arr in arrays for item in arr)
# Convert the set back to a list, if you need a list format
merged_list = list(unique_values)
return merged_list

def merge_prompts(*prompts):
# Split each prompt into a list, merge and remove duplicates
split_prompts = [prompt.split(", ") for prompt in prompts]
merged = merge_unique(split_prompts)
return ", ".join(merged)

def merge_styles(*style_lists):
# Merge and remove duplicates from style lists
return merge_unique(style_lists)

def trigger_describe(mode, img, current_prompt, current_style_selections):
if mode == flags.desc_type_all:
anime_desc, anime_styles = describe_anime(img)
photo_desc, photo_styles = describe_photo(img)

# Merge prompts and styles
merged_prompts = merge_prompts(current_prompt, anime_desc, photo_desc)
merged_style_selections = merge_styles(current_style_selections, anime_styles, photo_styles)

return merged_prompts, merged_style_selections

def trigger_describe(mode, img):
if mode == flags.desc_type_photo:
from extras.interrogate import default_interrogator as default_interrogator_photo
return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
return describe_photo(img)

if mode == flags.desc_type_anime:
from extras.wd14tagger import default_interrogator as default_interrogator_anime
return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
return describe_anime(img)

return mode, ["Fooocus V2"]

desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image],
desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image, prompt, style_selections],
outputs=[prompt, style_selections], show_progress=True, queue=True)


def dump_default_english_config():
from modules.localization import dump_english_config
dump_english_config(grh.all_components)
Expand Down