Babajaan commited on
Commit
ae2835b
·
verified ·
1 Parent(s): 22e1504

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -891,9 +891,31 @@ def main():
891
  app = create_gradio_interface()
892
 
893
  # Launch the app
894
- # For Hugging Face Spaces, use environment variable for port
895
  import os
896
- port = int(os.environ.get("GRADIO_SERVER_PORT", 7860))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
897
 
898
  app.launch(
899
  server_name="0.0.0.0",
 
891
  app = create_gradio_interface()
892
 
893
  # Launch the app
894
+ # For Hugging Face Spaces, try different port configurations
895
  import os
896
+ import socket
897
+
898
+ def find_free_port():
899
+ """Find a free port starting from 7860"""
900
+ for port in range(7860, 7870):
901
+ try:
902
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
903
+ s.bind(('', port))
904
+ return port
905
+ except OSError:
906
+ continue
907
+ return None
908
+
909
+ # Try environment variable first, then find free port
910
+ port = os.environ.get("GRADIO_SERVER_PORT")
911
+ if port:
912
+ port = int(port)
913
+ else:
914
+ port = find_free_port()
915
+ if not port:
916
+ port = 7860 # fallback
917
+
918
+ print(f"Starting server on port {port}")
919
 
920
  app.launch(
921
  server_name="0.0.0.0",