Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Add: serve loading page while Streamlit boots
Browse files
start.sh
CHANGED
|
@@ -1,4 +1,42 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
#
|
|
|
|
|
|
|
| 3 |
python scheduler.py &
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
# Serve loading page on 8501 while Streamlit boots on 8502,
|
| 3 |
+
# then switch Streamlit to 8501 once ready.
|
| 4 |
+
|
| 5 |
python scheduler.py &
|
| 6 |
+
|
| 7 |
+
# Start Streamlit on temp port 8502
|
| 8 |
+
streamlit run streamlit_app.py --server.port=8502 --server.address=0.0.0.0 &
|
| 9 |
+
STREAMLIT_PID=$!
|
| 10 |
+
|
| 11 |
+
# Serve loading.html on 8501 while waiting
|
| 12 |
+
python3 -c "
|
| 13 |
+
import http.server, urllib.request, time, sys
|
| 14 |
+
|
| 15 |
+
class Handler(http.server.BaseHTTPRequestHandler):
|
| 16 |
+
def do_GET(self):
|
| 17 |
+
self.send_response(200)
|
| 18 |
+
self.send_header('Content-type', 'text/html')
|
| 19 |
+
self.end_headers()
|
| 20 |
+
with open('/app/loading.html', 'rb') as f:
|
| 21 |
+
self.wfile.write(f.read())
|
| 22 |
+
def log_message(self, *args): pass
|
| 23 |
+
|
| 24 |
+
server = http.server.HTTPServer(('0.0.0.0', 8501), Handler)
|
| 25 |
+
server.timeout = 1
|
| 26 |
+
|
| 27 |
+
# Poll until Streamlit on 8502 is healthy
|
| 28 |
+
while True:
|
| 29 |
+
try:
|
| 30 |
+
urllib.request.urlopen('http://localhost:8502/_stcore/health', timeout=1)
|
| 31 |
+
break
|
| 32 |
+
except Exception:
|
| 33 |
+
server.handle_request()
|
| 34 |
+
|
| 35 |
+
server.server_close()
|
| 36 |
+
print('Streamlit ready — switching ports')
|
| 37 |
+
"
|
| 38 |
+
|
| 39 |
+
# Kill Streamlit on 8502, relaunch on 8501
|
| 40 |
+
kill $STREAMLIT_PID 2>/dev/null
|
| 41 |
+
wait $STREAMLIT_PID 2>/dev/null
|
| 42 |
+
exec streamlit run streamlit_app.py --server.port=8501 --server.address=0.0.0.0
|