[Fooocus 2.0.50] Variation/Upscale (Midjourney Toolbar) (#389)

This commit is contained in:
lllyasviel
2023-09-16 03:29:41 -07:00
committed by GitHub
parent 58c29aed00
commit 8ef31d33af
15 changed files with 446 additions and 100 deletions
+37 -14
View File
@@ -7,13 +7,14 @@ import modules.path
import fooocus_version
import modules.html
import modules.async_worker as worker
import modules.flags as flags
import comfy.model_management as model_management
from modules.sdxl_styles import style_keys, aspect_ratios, fooocus_expansion, default_styles
def generate_clicked(*args):
yield gr.update(interactive=False), \
gr.update(visible=True, value=modules.html.make_progress_html(1, 'Initializing ...')), \
yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Initializing ...')), \
gr.update(visible=True, value=None), \
gr.update(visible=False)
@@ -26,13 +27,11 @@ def generate_clicked(*args):
flag, product = worker.outputs.pop(0)
if flag == 'preview':
percentage, title, image = product
yield gr.update(interactive=False), \
gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \
yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \
gr.update(visible=True, value=image) if image is not None else gr.update(), \
gr.update(visible=False)
if flag == 'results':
yield gr.update(interactive=True), \
gr.update(visible=False), \
yield gr.update(visible=False), \
gr.update(visible=False), \
gr.update(visible=True, value=product)
finished = True
@@ -50,9 +49,28 @@ with shared.gradio_root:
with gr.Column(scale=0.85):
prompt = gr.Textbox(show_label=False, placeholder="Type prompt here.", container=False, autofocus=True, elem_classes='type_row', lines=1024)
with gr.Column(scale=0.15, min_width=0):
run_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row')
with gr.Row():
advanced_checkbox = gr.Checkbox(label='Advanced', value=False, container=False)
run_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', visible=True)
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row', visible=False)
def stop_clicked():
model_management.interrupt_current_processing()
return gr.update(interactive=False)
stop_button.click(stop_clicked, outputs=stop_button, queue=False)
with gr.Row(elem_classes='advanced_check_row'):
input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
advanced_checkbox = gr.Checkbox(label='Advanced', value=False, container=False, elem_classes='min_check')
with gr.Row(visible=False) as image_input_panel:
with gr.Column(scale=0.5):
with gr.Accordion(label='Upscale or Variation', open=True):
uov_input_image = gr.Image(label='Drag above image to here', source='upload', type='numpy')
uov_method = gr.Radio(label='Method', choices=flags.uov_list, value=flags.disabled, show_label=False, container=False)
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/390">\U0001F4D4 Document</a>')
input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox, outputs=image_input_panel, queue=False)
# def get_select_index(g, evt: gr.SelectData):
# return g[evt.index]['name']
# gallery.select(get_select_index, gallery, uov_input_image)
with gr.Column(scale=0.5, visible=False) as right_col:
with gr.Tab(label='Setting'):
performance_selction = gr.Radio(label='Performance', choices=['Speed', 'Quality'], value='Speed')
@@ -73,7 +91,7 @@ with shared.gradio_root:
else:
return s
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed])
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], queue=False)
with gr.Tab(label='Style'):
style_selections = gr.CheckboxGroup(show_label=False, container=False,
@@ -105,16 +123,21 @@ with shared.gradio_root:
results += [gr.update(choices=['None'] + modules.path.lora_filenames), gr.update()]
return results
model_refresh.click(model_refresh_clicked, [], [base_model, refiner_model] + lora_ctrls)
model_refresh.click(model_refresh_clicked, [], [base_model, refiner_model] + lora_ctrls, queue=False)
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, right_col)
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, right_col, queue=False)
ctrls = [
prompt, negative_prompt, style_selections,
performance_selction, aspect_ratios_selction, image_number, image_seed, sharpness
]
ctrls += [base_model, refiner_model] + lora_ctrls
run_button.click(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed)\
.then(fn=generate_clicked, inputs=ctrls, outputs=[run_button, progress_html, progress_window, gallery])
ctrls += [input_image_checkbox]
ctrls += [uov_method, uov_input_image]
run_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, run_button, gallery])\
.then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed)\
.then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, gallery])\
.then(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[run_button, stop_button])
parser = argparse.ArgumentParser()