@@ -65,6 +65,9 @@ def setupArgParser():
65
65
parser .add_argument ("--rmvpe" , type = str , default = "pretrain/rmvpe.pt" , help = "path to rmvpe" )
66
66
parser .add_argument ("--rmvpe_onnx" , type = str , default = "pretrain/rmvpe.onnx" , help = "path to rmvpe onnx" )
67
67
68
+ parser .add_argument ("--host" , type = str , default = '127.0.0.1' , help = "IP address of the network interface to listen for HTTP connections. Specify 0.0.0.0 to listen on all interfaces." )
69
+ parser .add_argument ("--allowed-origins" , action = 'append' , default = [], help = "List of URLs to allow connection from, i.e. https://example.com. Allows http(s)://127.0.0.1:{port} and http(s)://localhost:{port} by default." )
70
+
68
71
return parser
69
72
70
73
@@ -114,16 +117,19 @@ def printMessage(message, level=0):
114
117
115
118
printMessage (f"Booting PHASE :{ __name__ } " , level = 2 )
116
119
120
+ HOST = args .host
117
121
PORT = args .p
118
122
119
123
120
- def localServer (logLevel : str = "critical" ):
124
+ def localServer (logLevel : str = "critical" , key_path : str | None = None , cert_path : str | None = None ):
121
125
try :
122
126
uvicorn .run (
123
127
f"{ os .path .basename (__file__ )[:- 3 ]} :app_socketio" ,
124
- host = "0.0.0.0" ,
128
+ host = HOST ,
125
129
port = int (PORT ),
126
130
reload = False if hasattr (sys , "_MEIPASS" ) else True ,
131
+ ssl_keyfile = key_path ,
132
+ ssl_certfile = cert_path ,
127
133
log_level = logLevel ,
128
134
)
129
135
except Exception as e :
@@ -134,7 +140,7 @@ def localServer(logLevel: str = "critical"):
134
140
mp .freeze_support ()
135
141
136
142
voiceChangerManager = VoiceChangerManager .get_instance (voiceChangerParams )
137
- app_fastapi = MMVC_Rest .get_instance (voiceChangerManager , voiceChangerParams )
143
+ app_fastapi = MMVC_Rest .get_instance (voiceChangerManager , voiceChangerParams , PORT , args . allowed_origins )
138
144
app_socketio = MMVC_SocketIOApp .get_instance (app_fastapi , voiceChangerManager )
139
145
140
146
@@ -220,34 +226,26 @@ def localServer(logLevel: str = "critical"):
220
226
printMessage ("In many cases, it will launch when you access any of the following URLs." , level = 2 )
221
227
if "EX_PORT" in locals () and "EX_IP" in locals (): # シェルスクリプト経由起動(docker)
222
228
if args .https == 1 :
223
- printMessage (f"https://127.0.0.1 :{ EX_PORT } /" , level = 1 )
229
+ printMessage (f"https://localhost :{ EX_PORT } /" , level = 1 )
224
230
for ip in EX_IP .strip ().split (" " ):
225
231
printMessage (f"https://{ ip } :{ EX_PORT } /" , level = 1 )
226
232
else :
227
- printMessage (f"http://127.0.0.1 :{ EX_PORT } /" , level = 1 )
233
+ printMessage (f"http://localhost :{ EX_PORT } /" , level = 1 )
228
234
else : # 直接python起動
229
235
if args .https == 1 :
230
236
s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
231
237
s .connect ((args .test_connect , 80 ))
232
238
hostname = s .getsockname ()[0 ]
233
- printMessage (f"https://127.0.0.1 :{ PORT } /" , level = 1 )
239
+ printMessage (f"https://localhost :{ PORT } /" , level = 1 )
234
240
printMessage (f"https://{ hostname } :{ PORT } /" , level = 1 )
235
241
else :
236
- printMessage (f"http://127.0.0.1 :{ PORT } /" , level = 1 )
242
+ printMessage (f"http://localhost :{ PORT } /" , level = 1 )
237
243
238
244
# サーバ起動
239
245
if args .https :
240
246
# HTTPS サーバ起動
241
247
try :
242
- uvicorn .run (
243
- f"{ os .path .basename (__file__ )[:- 3 ]} :app_socketio" ,
244
- host = "0.0.0.0" ,
245
- port = int (PORT ),
246
- reload = False if hasattr (sys , "_MEIPASS" ) else True ,
247
- ssl_keyfile = key_path ,
248
- ssl_certfile = cert_path ,
249
- log_level = args .logLevel ,
250
- )
248
+ localServer (args .logLevel , key_path , cert_path )
251
249
except Exception as e :
252
250
logger .error (f"[Voice Changer] Web Server(https) Launch Exception, { e } " )
253
251
@@ -256,12 +254,12 @@ def localServer(logLevel: str = "critical"):
256
254
p .start ()
257
255
try :
258
256
if sys .platform .startswith ("win" ):
259
- process = subprocess .Popen ([NATIVE_CLIENT_FILE_WIN , "--disable-gpu" , "-u" , f"http://127.0.0.1 :{ PORT } /" ])
257
+ process = subprocess .Popen ([NATIVE_CLIENT_FILE_WIN , "--disable-gpu" , "-u" , f"http://localhost :{ PORT } /" ])
260
258
return_code = process .wait ()
261
259
logger .info ("client closed." )
262
260
p .terminate ()
263
261
elif sys .platform .startswith ("darwin" ):
264
- process = subprocess .Popen ([NATIVE_CLIENT_FILE_MAC , "--disable-gpu" , "-u" , f"http://127.0.0.1 :{ PORT } /" ])
262
+ process = subprocess .Popen ([NATIVE_CLIENT_FILE_MAC , "--disable-gpu" , "-u" , f"http://localhost :{ PORT } /" ])
265
263
return_code = process .wait ()
266
264
logger .info ("client closed." )
267
265
p .terminate ()
0 commit comments