Skip to content

Commit e9a5562

Browse files
committed
add support for tls (gradio tls options)
1 parent 30b1bcc commit e9a5562

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

modules/shared.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
parser.add_argument("--ui-debug-mode", action='store_true', help="Don't load model to quickly launch UI")
8787
parser.add_argument("--device-id", type=str, help="Select the default CUDA device to use (export CUDA_VISIBLE_DEVICES=0,1,etc might be needed before)", default=None)
8888
parser.add_argument("--administrator", action='store_true', help="Administrator rights", default=False)
89+
parser.add_argument("--tls-keyfile", type=str, help="Partially enables TLS, requires --tls-certfile to fully function", default=None)
90+
parser.add_argument("--tls-certfile", type=str, help="Partially enables TLS, requires --tls-keyfile to fully function", default=None)
91+
parser.add_argument("--server-name", type=str, help="Sets hostname of server", default=None)
8992

9093
cmd_opts = parser.parse_args()
9194
restricted_opts = {

webui.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import modules.hypernetworks.hypernetwork
3535

3636
queue_lock = threading.Lock()
37-
37+
server_name = "0.0.0.0" if cmd_opts.listen else cmd_opts.server_name
3838

3939
def wrap_queued_call(func):
4040
def f(*args, **kwargs):
@@ -85,6 +85,22 @@ def initialize():
8585
shared.opts.onchange("sd_hypernetwork", wrap_queued_call(lambda: modules.hypernetworks.hypernetwork.load_hypernetwork(shared.opts.sd_hypernetwork)))
8686
shared.opts.onchange("sd_hypernetwork_strength", modules.hypernetworks.hypernetwork.apply_strength)
8787

88+
if cmd_opts.tls_keyfile is not None and cmd_opts.tls_keyfile is not None:
89+
90+
try:
91+
if not os.path.exists(cmd_opts.tls_keyfile):
92+
print("Invalid path to TLS keyfile given")
93+
if not os.path.exists(cmd_opts.tls_certfile):
94+
print(f"Invalid path to TLS certfile: '{cmd_opts.tls_certfile}'")
95+
except TypeError:
96+
cmd_opts.tls_keyfile = cmd_opts.tls_certfile = None
97+
print(f"path: '{cmd_opts.tls_keyfile}' {type(cmd_opts.tls_keyfile)}")
98+
print(f"path: '{cmd_opts.tls_certfile}' {type(cmd_opts.tls_certfile)}")
99+
print("TLS setup invalid, running webui without TLS")
100+
else:
101+
print("Running with TLS")
102+
103+
88104
# make the program just exit at ctrl+c without waiting for anything
89105
def sigint_handler(sig, frame):
90106
print(f'Interrupted with signal {sig} in {frame}')
@@ -131,8 +147,10 @@ def webui():
131147

132148
app, local_url, share_url = demo.launch(
133149
share=cmd_opts.share,
134-
server_name="0.0.0.0" if cmd_opts.listen else None,
150+
server_name=server_name,
135151
server_port=cmd_opts.port,
152+
ssl_keyfile=cmd_opts.tls_keyfile,
153+
ssl_certfile=cmd_opts.tls_certfile,
136154
debug=cmd_opts.gradio_debug,
137155
auth=[tuple(cred.split(':')) for cred in cmd_opts.gradio_auth.strip('"').split(',')] if cmd_opts.gradio_auth else None,
138156
inbrowser=cmd_opts.autolaunch,

0 commit comments

Comments
 (0)