Spaces:
Sleeping
Sleeping
Delete huggingface-space-launcher.py
Browse files
huggingface-space-launcher.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
import sys
|
| 4 |
-
|
| 5 |
-
# This script is designed to properly launch the Streamlit app on Hugging Face Spaces
|
| 6 |
-
# It ensures the correct port binding and server address
|
| 7 |
-
|
| 8 |
-
def launch_streamlit():
|
| 9 |
-
print("Launching CodeBuddy AI on Hugging Face Space")
|
| 10 |
-
|
| 11 |
-
# Set environment variables for Streamlit
|
| 12 |
-
os.environ["STREAMLIT_SERVER_PORT"] = "7860"
|
| 13 |
-
os.environ["STREAMLIT_SERVER_ADDRESS"] = "0.0.0.0"
|
| 14 |
-
os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
|
| 15 |
-
os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "true"
|
| 16 |
-
os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
|
| 17 |
-
|
| 18 |
-
# Command to run Streamlit with correct parameters
|
| 19 |
-
cmd = [
|
| 20 |
-
"streamlit", "run", "app.py",
|
| 21 |
-
"--server.port=7860",
|
| 22 |
-
"--server.address=0.0.0.0",
|
| 23 |
-
"--server.enableCORS=true",
|
| 24 |
-
"--server.enableXsrfProtection=false",
|
| 25 |
-
"--browser.serverAddress=0.0.0.0"
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
# If we're running inside Docker or similar containerized environment
|
| 29 |
-
if os.environ.get("CONTAINER_MODE"):
|
| 30 |
-
print("Running in container mode")
|
| 31 |
-
|
| 32 |
-
# Execute the command and wait for completion
|
| 33 |
-
process = subprocess.Popen(cmd)
|
| 34 |
-
|
| 35 |
-
try:
|
| 36 |
-
# Wait for the process to complete
|
| 37 |
-
process.wait()
|
| 38 |
-
except KeyboardInterrupt:
|
| 39 |
-
# Handle Ctrl+C gracefully
|
| 40 |
-
print("Shutting down gracefully...")
|
| 41 |
-
process.terminate()
|
| 42 |
-
process.wait()
|
| 43 |
-
sys.exit(0)
|
| 44 |
-
except Exception as e:
|
| 45 |
-
print(f"Error: {e}")
|
| 46 |
-
process.terminate()
|
| 47 |
-
process.wait()
|
| 48 |
-
sys.exit(1)
|
| 49 |
-
|
| 50 |
-
if __name__ == "__main__":
|
| 51 |
-
launch_streamlit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|