khirodsahoo93 commited on
Commit
5bc95f5
Β·
verified Β·
1 Parent(s): af21194

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -20
app.py CHANGED
@@ -475,25 +475,39 @@ def create_interface():
475
  if __name__ == "__main__":
476
  app = create_interface()
477
 
478
- def find_free_port():
479
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
480
- s.bind(('', 0))
481
- s.listen(1)
482
- port = s.getsockname()[1]
483
- return port
484
 
485
- free_port = find_free_port()
486
- print(f"πŸš€ Launching Python to C++ Code Optimizer on port: {free_port}")
487
- print(f"πŸ” Password protection enabled. Password: {APP_PASSWORD}")
488
-
489
- # Launch with authentication
490
- app.launch(
491
- inbrowser=True,
492
- share=False,
493
- server_name="127.0.0.1",
494
- server_port=free_port,
495
- show_error=True,
496
- auth=("user", APP_PASSWORD), # Simple username/password
497
- auth_message="πŸ” Enter credentials to access the Python to C++ Code Optimizer"
498
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
 
 
475
  if __name__ == "__main__":
476
  app = create_interface()
477
 
478
+ # Check if running on Hugging Face Spaces
479
+ is_huggingface = os.getenv("SPACE_ID") is not None
 
 
 
 
480
 
481
+ if is_huggingface:
482
+ # Hugging Face Spaces configuration
483
+ print(f"πŸš€ Launching Python to C++ Code Optimizer on Hugging Face Spaces")
484
+ print(f"πŸ” Password protection enabled")
485
+
486
+ app.launch(
487
+ auth=("user", APP_PASSWORD),
488
+ auth_message="πŸ” Enter credentials to access the Python to C++ Code Optimizer"
489
+ )
490
+ else:
491
+ # Local development configuration
492
+ def find_free_port():
493
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
494
+ s.bind(('', 0))
495
+ s.listen(1)
496
+ port = s.getsockname()[1]
497
+ return port
498
+
499
+ free_port = find_free_port()
500
+ print(f"πŸš€ Launching Python to C++ Code Optimizer on port: {free_port}")
501
+ print(f"πŸ” Password protection enabled")
502
+
503
+ # Launch with authentication
504
+ app.launch(
505
+ inbrowser=True,
506
+ share=False,
507
+ server_name="127.0.0.1",
508
+ server_port=free_port,
509
+ show_error=True,
510
+ auth=("user", APP_PASSWORD),
511
+ auth_message="πŸ” Enter credentials to access the Python to C++ Code Optimizer"
512
+ )
513