Alikestocode commited on
Commit
1b04006
·
1 Parent(s): aa65d00

Add Cloud Run PORT environment variable support

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -924,9 +924,14 @@ _prefetch_from_env()
924
  demo = build_ui()
925
 
926
  if __name__ == "__main__": # pragma: no cover
 
 
 
 
 
927
  demo.launch(
928
- server_name="0.0.0.0",
929
- server_port=int(os.environ.get("PORT", 7860)),
930
  show_api=True
931
  )
932
 
 
924
  demo = build_ui()
925
 
926
  if __name__ == "__main__": # pragma: no cover
927
+ # Support both Hugging Face Spaces and Google Cloud Run
928
+ # Cloud Run uses PORT, Hugging Face Spaces uses GRADIO_SERVER_PORT
929
+ port = int(os.environ.get("PORT", os.environ.get("GRADIO_SERVER_PORT", 7860)))
930
+ server_name = os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0")
931
+
932
  demo.launch(
933
+ server_name=server_name,
934
+ server_port=port,
935
  show_api=True
936
  )
937