Skip to content

Commit

Permalink
Add --user and --password arguments for gradio auth'. Either both or …
Browse files Browse the repository at this point in the history
…neither required.
  • Loading branch information
robballantyne committed Jun 19, 2023
1 parent 7dcd440 commit f07fadd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,18 @@ def initialise(self):

self.app.queue()

def run(self, share, nobrowser, lan):
def get_auth_value(self, user, password):
if not user or not password:
return None
return (user[0], password[0])

def run(self, share, nobrowser, lan, user, password):
server_name = "0.0.0.0" if lan else None
self.initialise()
self.app.launch(
quiet=True,
share=share,
auth=self.get_auth_value(user, password),
inbrowser=not nobrowser,
server_name=server_name,
prevent_thread_lock=True,
Expand All @@ -906,7 +912,10 @@ def run(self, share, nobrowser, lan):
parser.add_argument("--share", action="store_true", help="Create a public URL")
parser.add_argument("--no-browser", action="store_true", help="Don't open automatically in a web browser")
parser.add_argument("--lan", action="store_true", help="Allow access on the local network")
parser.add_argument("--user", action="store", nargs=1, help="Username for authentication")
parser.add_argument("--password", action="store", nargs=1, help="Password for authentication")
args = parser.parse_args()

if args.user and not args.password or args.password and not args.user:
parser.error("--user and --password must both be specified")
ui = WebUI()
ui.run(args.share, args.no_browser, args.lan)
ui.run(args.share, args.no_browser, args.lan, args.user, args.password)

0 comments on commit f07fadd

Please sign in to comment.