mirror of
https://github.com/sd-webui/stable-diffusion-webui.git
synced 2024-12-14 23:02:00 +03:00
Changed relauncher.py to have easier to set arguments for users, added --inbrowser as an argument choice (#494)
* Changed relauncher.py to have easier to set arguments for users, added inbrowser as an argument choice Changed `relauncher.py` to have easier to set argument parameters for users to change. No longer is editing the main `os.system` string needed. Now, users can choose to set some of the commonly used arguments (totally open to more additions here) to be True or False, with an added area for users to enter their own custom arguments as desired. This really should make it easier for users to toggle what parameters they wish to launch with, and prevents them from needing to edit the main launch string for the `webui.py` file. Addition changes to `relauncher.py` include increasing the relaunch time from 0.5 seconds to 1 second, to allow for easier program closing from the Terminal. Changed `webui.py` to now include an `--inbrowser` argument to open the interface automatically in a user's default browser. The default is set to `False`. Gradio params have also now been alphabetised. A notice was given to users waiting for port 7860 to open that it may take upwards of 60 seconds to become available. * Added comments to describe what the changeable common arguments in relauncher.py do * Changed relauncher.py to fit with requested changes Added timeout for relauncher loop Changed inbrowser argument variable to be more understandable Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
This commit is contained in:
parent
66aca5c946
commit
9dc6aa4804
@ -1,11 +1,64 @@
|
||||
import os, time
|
||||
|
||||
# USER CHANGABLE ARGUMENTS
|
||||
|
||||
# Change to `True` if you wish to enable these common arguments
|
||||
|
||||
# Run upscaling models on the CPU
|
||||
extra_models_cpu = False
|
||||
|
||||
# Automatically open a new browser window or tab on first launch
|
||||
open_in_browser = False
|
||||
|
||||
# Run Stable Diffusion in Optimized Mode - Only requires 4Gb of VRAM, but is significantly slower
|
||||
optimized = False
|
||||
|
||||
# Run in Optimized Turbo Mode - Needs more VRAM than regular optimized mode, but is faster
|
||||
optimized_turbo = False
|
||||
|
||||
# Creates a public xxxxx.gradio.app share link to allow others to use your interface (requires properly forwarded ports to work correctly)
|
||||
share = False
|
||||
|
||||
|
||||
# Enter other `--arguments` you wish to use - Must be entered as a `--argument ` syntax
|
||||
additional_arguments = ""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# BEGIN RELAUNCHER PYTHON CODE
|
||||
|
||||
common_arguments = ""
|
||||
|
||||
if extra_models_cpu == True:
|
||||
common_arguments += "--extra-models-cpu "
|
||||
if optimized_turbo == True:
|
||||
common_arguments += "--optimized-turbo "
|
||||
if optimized == True:
|
||||
common_arguments += "--optimized "
|
||||
if share == True:
|
||||
common_arguments += "--share "
|
||||
|
||||
if open_in_browser == True:
|
||||
inbrowser_argument = "--inbrowser "
|
||||
else:
|
||||
inbrowser_argument = ""
|
||||
|
||||
n = 0
|
||||
while True:
|
||||
print('Relauncher: Launching...')
|
||||
if n > 0:
|
||||
if n == 0:
|
||||
print('Relauncher: Launching...')
|
||||
os.system(f"python scripts/webui.py {common_arguments} {inbrowser_argument} {additional_arguments}")
|
||||
|
||||
else:
|
||||
print(f'\tRelaunch count: {n}')
|
||||
os.system("python scripts/webui.py")
|
||||
print('Relauncher: Process is ending. Relaunching in 0.5s...')
|
||||
print('Relauncher: Launching...')
|
||||
os.system(f"python scripts/webui.py {common_arguments} {additional_arguments}")
|
||||
|
||||
n += 1
|
||||
time.sleep(0.5)
|
||||
if n > 100:
|
||||
print ('Too many relaunch attempts. Aborting...')
|
||||
break
|
||||
print('Relauncher: Process is ending. Relaunching in 1s...')
|
||||
time.sleep(1)
|
||||
|
8
webui.py
8
webui.py
@ -17,6 +17,7 @@ parser.add_argument("--gfpgan-dir", type=str, help="GFPGAN directory", default=(
|
||||
parser.add_argument("--gfpgan-gpu", type=int, help="run GFPGAN on specific gpu (overrides --gpu) ", default=0)
|
||||
parser.add_argument("--gpu", type=int, help="choose which GPU to use if you have multiple", default=0)
|
||||
parser.add_argument("--grid-format", type=str, help="png for lossless png files; jpg:quality for lossy jpeg; webp:quality for lossy webp, or webp:-compression for lossless webp", default="jpg:95")
|
||||
parser.add_argument("--inbrowser", action='store_true', help="automatically launch the interface in a new tab on the default browser", default=False)
|
||||
parser.add_argument("--ldsr-dir", type=str, help="LDSR directory", default=('./src/latent-diffusion' if os.path.exists('./src/latent-diffusion') else './LDSR'))
|
||||
parser.add_argument("--n_rows", type=int, default=-1, help="rows in the grid; use -1 for autodetect and 0 for n_rows to be same as batch_size (default: -1)",)
|
||||
parser.add_argument("--no-half", action='store_true', help="do not switch the model to 16-bit floats", default=False)
|
||||
@ -2098,10 +2099,11 @@ class ServerLauncher(threading.Thread):
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
gradio_params = {
|
||||
'show_error': True,
|
||||
'inbrowser': opt.inbrowser,
|
||||
'server_name': '0.0.0.0',
|
||||
'server_port': opt.port,
|
||||
'share': opt.share
|
||||
'share': opt.share,
|
||||
'show_error': True
|
||||
}
|
||||
if not opt.share:
|
||||
demo.queue(concurrency_count=opt.max_jobs)
|
||||
@ -2114,7 +2116,7 @@ class ServerLauncher(threading.Thread):
|
||||
try:
|
||||
self.demo.launch(**gradio_params)
|
||||
except (OSError) as e:
|
||||
print (f'Error: Port: {opt.port} is not open yet. Please wait...')
|
||||
print (f'Error: Port: {opt.port} is not open yet. Please wait, this may take upwards of 60 seconds...')
|
||||
time.sleep(10)
|
||||
else:
|
||||
port_status = 0
|
||||
|
Loading…
Reference in New Issue
Block a user