mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
Merge pull request #5 from rayronvictor/feature/add-inpaint-mask-generation
Add options to u2net_cloth_seg, add u2net_human_seg again
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from rembg import remove, new_session
|
from rembg import remove, new_session
|
||||||
|
|
||||||
|
|
||||||
def generate_mask_from_image(image, mask_model):
|
def generate_mask_from_image(image, mask_model, extras):
|
||||||
if image is None:
|
if image is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -11,5 +11,6 @@ def generate_mask_from_image(image, mask_model):
|
|||||||
return remove(
|
return remove(
|
||||||
image,
|
image,
|
||||||
session=new_session(mask_model),
|
session=new_session(mask_model),
|
||||||
only_mask=True
|
only_mask=True,
|
||||||
|
**extras
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -324,6 +324,12 @@ default_inpaint_mask_model = get_config_item_or_set_default(
|
|||||||
validator=lambda x: x in modules.flags.inpaint_mask_models
|
validator=lambda x: x in modules.flags.inpaint_mask_models
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_inpaint_mask_cloth_category = get_config_item_or_set_default(
|
||||||
|
key='default_inpaint_mask_cloth_category',
|
||||||
|
default_value='full',
|
||||||
|
validator=lambda x: x in modules.flags.inpaint_mask_cloth_category
|
||||||
|
)
|
||||||
|
|
||||||
config_dict["default_loras"] = default_loras = default_loras[:5] + [['None', 1.0] for _ in range(5 - len(default_loras))]
|
config_dict["default_loras"] = default_loras = default_loras[:5] + [['None', 1.0] for _ in range(5 - len(default_loras))]
|
||||||
|
|
||||||
possible_preset_keys = [
|
possible_preset_keys = [
|
||||||
|
|||||||
+3
-1
@@ -36,9 +36,11 @@ inpaint_engine_versions = ['None', 'v1', 'v2.5', 'v2.6']
|
|||||||
performance_selections = ['Speed', 'Quality', 'Extreme Speed']
|
performance_selections = ['Speed', 'Quality', 'Extreme Speed']
|
||||||
|
|
||||||
inpaint_mask_models = [
|
inpaint_mask_models = [
|
||||||
'u2net', 'u2netp', 'silueta', 'isnet-general-use', 'isnet-anime'
|
'u2net', 'u2netp', 'u2net_human_seg', 'u2net_cloth_seg', 'silueta', 'isnet-general-use', 'isnet-anime'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
inpaint_mask_cloth_category = ['full', 'upper', 'lower']
|
||||||
|
|
||||||
inpaint_option_default = 'Inpaint or Outpaint (default)'
|
inpaint_option_default = 'Inpaint or Outpaint (default)'
|
||||||
inpaint_option_detail = 'Improve Detail (face, hand, eyes, etc.)'
|
inpaint_option_detail = 'Improve Detail (face, hand, eyes, etc.)'
|
||||||
inpaint_option_modify = 'Modify Content (add objects, change background, etc.)'
|
inpaint_option_modify = 'Modify Content (add objects, change background, etc.)'
|
||||||
|
|||||||
@@ -187,29 +187,48 @@ with shared.gradio_root:
|
|||||||
queue=False, show_progress=False)
|
queue=False, show_progress=False)
|
||||||
with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
|
with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
inpaint_input_image = grh.Image(label='Drag inpaint or outpaint image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas')
|
with gr.Column():
|
||||||
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', height=500, visible=False)
|
inpaint_input_image = grh.Image(label='Drag inpaint or outpaint image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas')
|
||||||
|
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
|
||||||
|
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
||||||
|
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
||||||
|
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts,
|
||||||
|
label='Additional Prompt Quick List',
|
||||||
|
components=[inpaint_additional_prompt],
|
||||||
|
visible=False)
|
||||||
|
gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
|
||||||
|
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Column(visible=False) as inpaint_mask_generation_col:
|
||||||
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy',
|
||||||
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
height=500, visible=False)
|
||||||
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
|
inpaint_mask_model = gr.Dropdown(label='Mask generation model',
|
||||||
with gr.Row(visible=False) as inpaint_mask_generation_row:
|
choices=flags.inpaint_mask_models,
|
||||||
inpaint_mask_model = gr.Dropdown(label='Mask generation model',
|
value=modules.config.default_inpaint_mask_model,
|
||||||
choices=flags.inpaint_mask_models,
|
visible=False)
|
||||||
value=modules.config.default_inpaint_mask_model, visible=False)
|
cloth_category = gr.Dropdown(label='Cloth category',
|
||||||
generate_mask_button = gr.Button(value='Generate mask from image', visible=False)
|
choices=flags.inpaint_mask_cloth_category,
|
||||||
|
value=modules.config.default_inpaint_mask_cloth_category,
|
||||||
|
visible=False)
|
||||||
|
generate_mask_button = gr.Button(value='Generate mask from image', visible=False)
|
||||||
|
|
||||||
def generate_mask(image, mask_model):
|
|
||||||
from extras.inpaint_mask import generate_mask_from_image
|
|
||||||
return generate_mask_from_image(image, mask_model)
|
|
||||||
|
|
||||||
generate_mask_button.click(fn=generate_mask, inputs=[inpaint_input_image, inpaint_mask_model],
|
def generate_mask(image, mask_model, cloth_category):
|
||||||
outputs=inpaint_mask_image)
|
from extras.inpaint_mask import generate_mask_from_image
|
||||||
|
return generate_mask_from_image(image, mask_model, extras={"cloth_category": cloth_category})
|
||||||
|
|
||||||
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False)
|
|
||||||
gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
|
generate_mask_button.click(fn=generate_mask,
|
||||||
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
|
inputs=[
|
||||||
|
inpaint_input_image, inpaint_mask_model,
|
||||||
|
cloth_category
|
||||||
|
],
|
||||||
|
outputs=inpaint_mask_image)
|
||||||
|
|
||||||
|
inpaint_mask_model.change(lambda x: gr.update(visible=x == 'u2net_cloth_seg'),
|
||||||
|
inputs=inpaint_mask_model,
|
||||||
|
outputs=cloth_category,
|
||||||
|
queue=False, show_progress=False)
|
||||||
with gr.TabItem(label='Describe') as desc_tab:
|
with gr.TabItem(label='Describe') as desc_tab:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
@@ -450,7 +469,7 @@ with shared.gradio_root:
|
|||||||
inpaint_mask_upload_checkbox.change(lambda x: [gr.update(visible=x)] * 4,
|
inpaint_mask_upload_checkbox.change(lambda x: [gr.update(visible=x)] * 4,
|
||||||
inputs=inpaint_mask_upload_checkbox,
|
inputs=inpaint_mask_upload_checkbox,
|
||||||
outputs=[inpaint_mask_image, generate_mask_button,
|
outputs=[inpaint_mask_image, generate_mask_button,
|
||||||
inpaint_mask_model, inpaint_mask_generation_row],
|
inpaint_mask_model, inpaint_mask_generation_col],
|
||||||
queue=False, show_progress=False)
|
queue=False, show_progress=False)
|
||||||
|
|
||||||
with gr.Tab(label='FreeU'):
|
with gr.Tab(label='FreeU'):
|
||||||
|
|||||||
Reference in New Issue
Block a user