Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
0f28aee9
Commit
0f28aee9
authored
May 19, 2023
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor gradio auth
parent
674e80c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
webui.py
webui.py
+29
-8
No files found.
webui.py
View file @
0f28aee9
...
...
@@ -7,6 +7,7 @@ import re
import
warnings
import
json
from
threading
import
Thread
from
typing
import
Iterable
from
fastapi
import
FastAPI
,
Response
from
fastapi.middleware.cors
import
CORSMiddleware
...
...
@@ -178,6 +179,32 @@ def validate_tls_options():
startup_timer
.
record
(
"TLS"
)
def
get_gradio_auth_creds
()
->
Iterable
[
tuple
[
str
,
...
]]:
"""
Convert the gradio_auth and gradio_auth_path commandline arguments into
an iterable of (username, password) tuples.
"""
def
process_credential_line
(
s
)
->
tuple
[
str
,
...
]
|
None
:
s
=
s
.
strip
()
if
not
s
:
return
None
return
tuple
(
s
.
split
(
':'
,
1
))
if
cmd_opts
.
gradio_auth
:
for
cred
in
cmd_opts
.
gradio_auth
.
split
(
','
):
cred
=
process_credential_line
(
cred
)
if
cred
:
yield
cred
if
cmd_opts
.
gradio_auth_path
:
with
open
(
cmd_opts
.
gradio_auth_path
,
'r'
,
encoding
=
"utf8"
)
as
file
:
for
line
in
file
.
readlines
():
for
cred
in
line
.
strip
()
.
split
(
','
):
cred
=
process_credential_line
(
cred
)
if
cred
:
yield
cred
def
configure_sigint_handler
():
# make the program just exit at ctrl+c without waiting for anything
def
sigint_handler
(
sig
,
frame
):
...
...
@@ -316,13 +343,7 @@ def webui():
if
not
cmd_opts
.
no_gradio_queue
:
shared
.
demo
.
queue
(
64
)
gradio_auth_creds
=
[]
if
cmd_opts
.
gradio_auth
:
gradio_auth_creds
+=
[
x
.
strip
()
for
x
in
cmd_opts
.
gradio_auth
.
strip
(
'"'
)
.
replace
(
'
\n
'
,
''
)
.
split
(
','
)
if
x
.
strip
()]
if
cmd_opts
.
gradio_auth_path
:
with
open
(
cmd_opts
.
gradio_auth_path
,
'r'
,
encoding
=
"utf8"
)
as
file
:
for
line
in
file
.
readlines
():
gradio_auth_creds
+=
[
x
.
strip
()
for
x
in
line
.
split
(
','
)
if
x
.
strip
()]
gradio_auth_creds
=
list
(
get_gradio_auth_creds
())
or
None
# this restores the missing /docs endpoint
if
launch_api
and
not
hasattr
(
FastAPI
,
'original_setup'
):
...
...
@@ -343,7 +364,7 @@ def webui():
ssl_certfile
=
cmd_opts
.
tls_certfile
,
ssl_verify
=
cmd_opts
.
disable_tls_verify
,
debug
=
cmd_opts
.
gradio_debug
,
auth
=
[
tuple
(
cred
.
split
(
':'
))
for
cred
in
gradio_auth_creds
]
if
gradio_auth_creds
else
None
,
auth
=
gradio_auth_creds
,
inbrowser
=
cmd_opts
.
autolaunch
,
prevent_thread_lock
=
True
,
allowed_paths
=
cmd_opts
.
gradio_allowed_path
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment