DevEmmy commited on
Commit
4bb4d57
·
1 Parent(s): 85d2c5b

Disable SSR and hold the process open

Browse files

Gradio 6 defaults to SSR, which fronts the public port with a Node proxy and
serves Python on 7861 behind it — routes grafted onto the Python app were
unreachable from outside. block_thread() also returned straight away and the
container exited, so wait explicitly.

Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -269,9 +269,21 @@ if __name__ == "__main__":
269
  server_port=int(os.environ.get("PORT", 7860)),
270
  prevent_thread_lock=True,
271
  show_error=True,
 
 
 
 
 
272
  )
273
  demo.app.router.routes[0:0] = app.router.routes
274
  print("REST routes attached: " +
275
  ", ".join(sorted(r.path for r in app.router.routes if hasattr(r, "methods"))),
276
  flush=True)
277
- demo.block_thread()
 
 
 
 
 
 
 
 
269
  server_port=int(os.environ.get("PORT", 7860)),
270
  prevent_thread_lock=True,
271
  show_error=True,
272
+ # SSR is Gradio 6's default and puts a Node proxy on the public port,
273
+ # serving Python on 7861 behind it. Routes grafted onto the Python app
274
+ # are then unreachable from outside, so the REST API has to have the
275
+ # public port to itself.
276
+ ssr_mode=False,
277
  )
278
  demo.app.router.routes[0:0] = app.router.routes
279
  print("REST routes attached: " +
280
  ", ".join(sorted(r.path for r in app.router.routes if hasattr(r, "methods"))),
281
  flush=True)
282
+ # block_thread() returned immediately here and the container exited; an
283
+ # explicit wait keeps the process alive for as long as the server runs.
284
+ try:
285
+ demo.block_thread()
286
+ except KeyboardInterrupt:
287
+ pass
288
+ else:
289
+ threading.Event().wait()