add tkinter launch for webui (#1364)

This commit is contained in:
Daniel Garvey
2023-04-27 19:17:55 -05:00
committed by GitHub
parent fb6f26517f
commit 9bdb86637d
4 changed files with 33 additions and 2 deletions

View File

@@ -29,6 +29,8 @@ datas += collect_data_files('gradio_client')
datas += collect_data_files('iree')
datas += collect_data_files('google-cloud-storage')
datas += collect_data_files('shark')
datas += collect_data_files('tkinter')
datas += collect_data_files('webview')
datas += [
( 'src/utils/resources/prompts.json', 'resources' ),
( 'src/utils/resources/model_db.json', 'resources' ),

View File

@@ -493,6 +493,13 @@ p.add_argument(
default="",
help="Path to directory where all .ckpts are stored in order to populate them in the web UI",
)
# TODO: replace API flag when these can be run together
p.add_argument(
"--web_mode",
type=str,
default="app",
help="any number of: [api, app, webui]. Currently api can't be run with others.",
)
p.add_argument(

View File

@@ -1,3 +1,4 @@
from multiprocessing import Process, freeze_support
import os
import sys
import transformers
@@ -10,8 +11,22 @@ if sys.platform == "darwin":
if args.clear_all:
clear_all()
def launch_app(address):
from tkinter import Tk
import webview
tk = Tk()
# size of the window where we show our website
tk.geometry("1280x720")
webview.create_window("SHARK", address)
webview.start(private_mode=False)
if __name__ == "__main__":
if args.api:
# required to do multiprocessing in a pyinstaller freeze
freeze_support()
if args.api or "api" in args.web_mode.split(","):
from apps.stable_diffusion.web.ui import (
txt2img_api,
img2img_api,
@@ -221,9 +236,14 @@ if __name__ == "__main__":
[outpaint_init_image, tabs],
)
sd_web.queue()
if "app" in args.web_mode.split(","):
t = Process(
target=launch_app, args=[f"http://localhost:{args.server_port}"]
)
t.start()
sd_web.launch(
share=args.share,
inbrowser=True,
inbrowser="webui" in args.web_mode.split(","),
server_name="0.0.0.0",
server_port=args.server_port,
)

View File

@@ -26,6 +26,8 @@ safetensors
opencv-python
scikit-image
pytorch_lightning # for runwayml models
tk
pywebview
# Keep PyInstaller at the end. Sometimes Windows Defender flags it but most folks can continue even if it errors
pefile