jsboige commited on
Commit
94f2c1b
1 Parent(s): 3a65e3d

Adding args for hostname, port and simple auth

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. user-start-webui.bat +32 -0
app.py CHANGED
@@ -149,16 +149,28 @@ class App:
149
  inputs=None,
150
  outputs=None)
151
 
 
152
  if self.args.share:
153
  self.app.queue(api_open=False).launch(share=True)
154
  else:
155
- self.app.queue(api_open=False).launch()
 
 
 
 
 
 
 
156
 
157
 
158
- # Create the parser
159
  parser = argparse.ArgumentParser()
160
  parser.add_argument('--share', type=bool, default=False, nargs='?', const=True,
161
  help='Share value')
 
 
 
 
162
  _args = parser.parse_args()
163
 
164
  if __name__ == "__main__":
 
149
  inputs=None,
150
  outputs=None)
151
 
152
+ # Launch the app with optional server settings
153
  if self.args.share:
154
  self.app.queue(api_open=False).launch(share=True)
155
  else:
156
+ launch_args = {}
157
+ if self.args.server_name:
158
+ launch_args['server_name'] = self.args.server_name
159
+ if self.args.server_port:
160
+ launch_args['server_port'] = self.args.server_port
161
+ if self.args.username and self.args.password:
162
+ launch_args['auth'] = (self.args.username, self.args.password)
163
+ self.app.queue(api_open=False).launch(**launch_args)
164
 
165
 
166
+ # Create the parser for command-line arguments
167
  parser = argparse.ArgumentParser()
168
  parser.add_argument('--share', type=bool, default=False, nargs='?', const=True,
169
  help='Share value')
170
+ parser.add_argument('--server_name', type=str, default=None, help='Gradio server host')
171
+ parser.add_argument('--server_port', type=int, default=None, help='Gradio server port')
172
+ parser.add_argument('--username', type=str, default=None, help='Authentication username')
173
+ parser.add_argument('--password', type=str, default=None, help='Authentication password')
174
  _args = parser.parse_args()
175
 
176
  if __name__ == "__main__":
user-start-webui.bat ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @echo off
2
+
3
+ :: Set default values
4
+ set SERVER_NAME=
5
+ set SERVER_PORT=
6
+ set USERNAME=
7
+ set PASSWORD=
8
+
9
+ :: Uncomment and set the values for the optional arguments
10
+
11
+ :: set SERVER_NAME=0.0.0.0
12
+ :: set SERVER_PORT=36540
13
+ :: set USERNAME=your_username
14
+ :: set PASSWORD=your_password
15
+
16
+ :: Check if the arguments are uncommented and set them accordingly
17
+ if not "%SERVER_NAME%"=="" (
18
+ set SERVER_NAME_ARG=--server_name %SERVER_NAME%
19
+ )
20
+ if not "%SERVER_PORT%"=="" (
21
+ set SERVER_PORT_ARG=--server_port %SERVER_PORT%
22
+ )
23
+ if not "%USERNAME%"=="" (
24
+ set USERNAME_ARG=--username %USERNAME%
25
+ )
26
+ if not "%PASSWORD%"=="" (
27
+ set PASSWORD_ARG=--password %PASSWORD%
28
+ )
29
+
30
+ :: Call the original .bat script with optional arguments
31
+ start-webui.bat %SERVER_NAME_ARG% %SERVER_PORT_ARG% %USERNAME_ARG% %PASSWORD_ARG%
32
+ pause