Update webui.py

pull/17044/head
Lucas Santos 2025-06-25 21:28:45 -03:00 committed by GitHub
parent 6b71b0ed83
commit 0e75f96b34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,9 @@
import os
import time
from pathlib import Path
from packaging.version import parse
import gradio
from modules import (
shared,
ui_tempdir,
@ -10,24 +14,26 @@ from modules import (
ui_extra_networks,
timer,
initialize,
script_callbacks
script_callbacks,
cmd_opts
)
from api import create_api # ajuste se create_api for de outro módulo
from packaging.version import parse
from pathlib import Path
import gradio
from api import create_api
def limpar_temp_dir():
if shared.opts.clean_temp_dir_at_start:
ui_tempdir.cleanup_tmpdr()
startup_timer.record("cleanup temp dir")
def configurar_ui():
shared.demo = ui.create_ui()
startup_timer.record("create ui")
if not cmd_opts.no_gradio_queue:
shared.demo.queue(64)
def decidir_autolancamento():
if os.getenv('SD_WEBUI_RESTARTING') == '1':
return False
@ -37,6 +43,7 @@ def decidir_autolancamento():
return not cmd_opts.webui_is_non_local
return False
def lancar_interface(auto_launch_browser):
gradio_auth_creds = list(initialize_util.get_gradio_auth_creds()) or None
return shared.demo.launch(
@ -55,12 +62,14 @@ def lancar_interface(auto_launch_browser):
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
)
def proteger_app(app):
app.user_middleware = [
x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware'
]
initialize_util.setup_middleware(app)
def configurar_apis(app):
progress.setup_progress_api(app)
ui.setup_ui_api(app)
@ -68,6 +77,7 @@ def configurar_apis(app):
create_api(app)
ui_extra_networks.add_pages_to_demo(app)
def monitorar_comandos():
while True:
server_command = shared.state.wait_for_server_command(timeout=5)
@ -77,6 +87,7 @@ def monitorar_comandos():
else:
print(f"Unknown server command: {server_command}")
def warning_if_invalid_install_dir():
if parse('3.32.0') <= parse(gradio.__version__) < parse('4'):
def abspath(path):
@ -90,11 +101,12 @@ def warning_if_invalid_install_dir():
print(f'''{"!"*25} Warning {"!"*25}
WebUI is installed in a directory that has a leading dot (.) in one of its parent directories.
This will prevent WebUI from functioning properly.
Please move the installation to a different directory.
Current path: "{webui_root}"
For more information see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
Please move the installation to a different directory.
More info: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
{"!"*25} Warning {"!"*25}''')
def webui():
initialize.initialize()
warning_if_invalid_install_dir()
@ -142,3 +154,7 @@ def webui():
script_callbacks.script_unloaded_callback()
startup_timer.record("scripts unloaded callback")
initialize.initialize_rest(reload_script_modules=True)
if __name__ == "__main__":
webui()