avans06 commited on
Commit
db45f59
1 Parent(s): a14fe5a

The app will now automatically search for an available port when the

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -1274,6 +1274,25 @@ def create_ui(app_config: ApplicationConfig):
1274
 
1275
  return transcribe
1276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1277
  def create_translation(isQueueMode: bool):
1278
  with gr.Blocks() as translation:
1279
  translateInput = gr.State(value="m2m100") # [Gradio 5.x] TypeError: State.__init__() got an unexpected keyword argument 'elem_id'
@@ -1346,7 +1365,7 @@ def create_ui(app_config: ApplicationConfig):
1346
  else:
1347
  print("Queue mode disabled - progress bars will not be shown.")
1348
 
1349
- demo.launch(inbrowser=app_config.autolaunch, share=app_config.share, server_name=app_config.server_name, server_port=app_config.server_port)
1350
 
1351
  # Clean up
1352
  ui.close()
 
1274
 
1275
  return transcribe
1276
 
1277
+ def find_free_port() -> int:
1278
+ server_name=app_config.server_name
1279
+ server_port=app_config.server_port
1280
+
1281
+ if server_name is None:
1282
+ server_name = '127.0.0.1'
1283
+
1284
+ if server_port is None:
1285
+ server_port = 7860
1286
+
1287
+ import socket
1288
+ while True:
1289
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
1290
+ try:
1291
+ s.bind((server_name, server_port))
1292
+ return server_port
1293
+ except OSError:
1294
+ server_port += 1
1295
+
1296
  def create_translation(isQueueMode: bool):
1297
  with gr.Blocks() as translation:
1298
  translateInput = gr.State(value="m2m100") # [Gradio 5.x] TypeError: State.__init__() got an unexpected keyword argument 'elem_id'
 
1365
  else:
1366
  print("Queue mode disabled - progress bars will not be shown.")
1367
 
1368
+ demo.launch(inbrowser=app_config.autolaunch, share=app_config.share, server_name=app_config.server_name, server_port=find_free_port())
1369
 
1370
  # Clean up
1371
  ui.close()