diff --git a/webui.py b/webui.py index 97f102c048..fb865c08a8 100644 --- a/webui.py +++ b/webui.py @@ -4,839 +4,112 @@ import json import time import shared -import modules.config +import modules.config as config import fooocus_version -import modules.html +import modules.html as html import modules.async_worker as worker import modules.constants as constants import modules.flags as flags import modules.gradio_hijack as grh import modules.style_sorter as style_sorter -import modules.meta_parser +import modules.meta_parser as meta_parser from modules.rembg import rembg_run import args_manager import copy import launch - -from modules.sdxl_styles import legal_style_names -from modules.private_logger import get_current_html_path -from modules.ui_gradio_extensions import reload_javascript -from modules.auth import auth_enabled, check_auth -from modules.util import is_json - -PHOTOPEA_MAIN_URL = "https://www.photopea.com/" -PHOTOPEA_IFRAME_ID = "webui-photopea-iframe" -PHOTOPEA_IFRAME_HEIGHT = 684 -PHOTOPEA_IFRAME_WIDTH = "100%" -PHOTOPEA_IFRAME_LOADED_EVENT = "onPhotopeaLoaded" - - -def get_photopea_url_params(): - return "#%7B%22resources%22:%5B%22data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAQMAAADOtka5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRF////p8QbyAAAADZJREFUeJztwQEBAAAAgiD/r25IQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfBuCAAAB0niJ8AAAAABJRU5ErkJggg==%22%5D%7D" - +from SegBody import segment_body def get_task(*args): args = list(args) args.pop(0) - return worker.AsyncTask(args=args) -def generate_clicked(task): - import ldm_patched.modules.model_management as model_management - - with model_management.interrupt_processing_mutex: - model_management.interrupt_processing = False - # outputs=[progress_html, progress_window, progress_gallery, gallery] - execution_start_time = time.perf_counter() - finished = False - - yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ - gr.update(visible=True, value=None), \ - gr.update(visible=False, value=None), \ - gr.update(visible=False) - - worker.async_tasks.append(task) - - while not finished: - time.sleep(0.01) - if len(task.yields) > 0: - flag, product = task.yields.pop(0) - if flag == 'preview': - - # help bad internet connection by skipping duplicated preview - if len(task.yields) > 0: # if we have the next item - if task.yields[0][0] == 'preview': # if the next item is also a preview - # print('Skipped one preview for better internet connection.') - continue - - percentage, title, image = product - 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(), \ - gr.update(visible=False) - if flag == 'results': - yield gr.update(visible=True), \ - gr.update(visible=True), \ - gr.update(visible=True, value=product), \ - gr.update(visible=False) - if flag == 'finish': - yield gr.update(visible=False), \ - gr.update(visible=False), \ - gr.update(visible=False), \ - gr.update(visible=True, value=product) - finished = True - - # delete Fooocus temp images, only keep gradio temp images - if args_manager.args.disable_image_log: - for filepath in product: - os.remove(filepath) - - execution_time = time.perf_counter() - execution_start_time - global time_taken - time_taken = f"Total time: {execution_time:.2f} seconds" - print(time_taken) - return - - -reload_javascript() - -title = f'DeFooocus {fooocus_version.version}' - -if isinstance(args_manager.args.preset, str): - title += ' ' + args_manager.args.preset - -shared.gradio_root = gr.Blocks( - title=title, - css=modules.html.css, - theme="ehristoforu/Indigo_Theme").queue() - -with shared.gradio_root: - currentTask = gr.State(worker.AsyncTask(args=[])) - with gr.Row(): - with gr.Column(scale=2): - with gr.Tab("Generation"): - with gr.Row(): - progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768, - elem_classes=['main_view']) - progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain', - height=768, visible=False, elem_classes=['main_view', 'image_gallery']) - progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False, - elem_id='progress-bar', elem_classes='progress-bar') - gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768, - elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'], - elem_id='final_gallery') - with gr.Tab("Photopea"): - with gr.Row(): - photopea = gr.HTML( - f"""