stable-diffusion-webui/relauncher.py
Joshua Kimsey 9dc6aa4804
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>
2022-09-03 08:35:25 +01:00

65 lines
1.8 KiB
Python

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:
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}')
print('Relauncher: Launching...')
os.system(f"python scripts/webui.py {common_arguments} {additional_arguments}")
n += 1
if n > 100:
print ('Too many relaunch attempts. Aborting...')
break
print('Relauncher: Process is ending. Relaunching in 1s...')
time.sleep(1)