import gradio as gr
from scripts.reactor_helpers import (
get_model_names,
get_facemodels
)
from scripts.reactor_swapper import (
clear_faces_list,
)
from modules import shared
SAVE_ORIGINAL: bool = False
def update_fm_list(selected: str):
return gr.Dropdown.update(
value=selected, choices=get_model_names(get_facemodels)
)
# TAB MAIN
def show(is_img2img: bool, show_br: bool = True, **msgs):
def on_select_source(selected: bool, evt: gr.SelectData):
global SAVE_ORIGINAL
if evt.index == 2:
if SAVE_ORIGINAL != selected:
SAVE_ORIGINAL = selected
return {
control_col_1: gr.Column.update(visible=False),
control_col_2: gr.Column.update(visible=False),
control_col_3: gr.Column.update(visible=True),
save_original: gr.Checkbox.update(value=False,visible=False),
imgs_hash_clear: gr.Button.update(visible=True)
}
if evt.index == 0:
return {
control_col_1: gr.Column.update(visible=True),
control_col_2: gr.Column.update(visible=False),
control_col_3: gr.Column.update(visible=False),
save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
imgs_hash_clear: gr.Button.update(visible=False)
}
if evt.index == 1:
return {
control_col_1: gr.Column.update(visible=False),
control_col_2: gr.Column.update(visible=True),
control_col_3: gr.Column.update(visible=False),
save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
imgs_hash_clear: gr.Button.update(visible=False)
}
progressbar_area = gr.Markdown("")
with gr.Tab("Main"):
with gr.Column():
with gr.Row():
select_source = gr.Radio(
["Image(s)","Face Model","Folder"],
value="Image(s)",
label="Select Source",
type="index",
scale=1,
)
with gr.Column(visible=False) as control_col_2:
with gr.Row():
face_models = get_model_names(get_facemodels)
face_model = gr.Dropdown(
choices=face_models,
label="Choose Face Model",
value="None",
scale=1,
)
fm_update = gr.Button(
value="🔄",
variant="tool",
)
fm_update.click(
update_fm_list,
inputs=[face_model],
outputs=[face_model],
)
imgs_hash_clear = gr.Button(
value="Clear Source Images Hash",
scale=1,
visible=False,
)
imgs_hash_clear.click(clear_faces_list,None,[progressbar_area])
gr.Markdown("
", visible=show_br)
with gr.Column(visible=True) as control_col_1:
gr.Markdown("