Spaces:
Sleeping
Sleeping
DaCrow13
commited on
Commit
·
cc2ed29
1
Parent(s):
8caf0a0
feat: Add `start_space.sh` script to automate application launch and separate Nginx FastAPI endpoint routing.
Browse files- nginx.conf +31 -5
- scripts/start_space.sh +7 -1
nginx.conf
CHANGED
|
@@ -32,16 +32,42 @@ http {
|
|
| 32 |
listen 7860;
|
| 33 |
server_name localhost;
|
| 34 |
|
| 35 |
-
# FastAPI
|
| 36 |
-
location
|
| 37 |
-
proxy_pass http://fastapi;
|
| 38 |
proxy_set_header Host $host;
|
| 39 |
proxy_set_header X-Real-IP $remote_addr;
|
| 40 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 41 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 42 |
}
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
location / {
|
| 46 |
proxy_pass http://streamlit;
|
| 47 |
proxy_set_header Host $host;
|
|
@@ -49,7 +75,7 @@ http {
|
|
| 49 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 50 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 51 |
|
| 52 |
-
#
|
| 53 |
proxy_http_version 1.1;
|
| 54 |
proxy_set_header Upgrade $http_upgrade;
|
| 55 |
proxy_set_header Connection "upgrade";
|
|
|
|
| 32 |
listen 7860;
|
| 33 |
server_name localhost;
|
| 34 |
|
| 35 |
+
# FastAPI Documentation
|
| 36 |
+
location /docs {
|
| 37 |
+
proxy_pass http://fastapi/docs;
|
| 38 |
proxy_set_header Host $host;
|
| 39 |
proxy_set_header X-Real-IP $remote_addr;
|
| 40 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 41 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 42 |
}
|
| 43 |
|
| 44 |
+
location /redoc {
|
| 45 |
+
proxy_pass http://fastapi/redoc;
|
| 46 |
+
proxy_set_header Host $host;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
location /openapi.json {
|
| 50 |
+
proxy_pass http://fastapi/openapi.json;
|
| 51 |
+
proxy_set_header Host $host;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
# FastAPI API Endpoints
|
| 55 |
+
location /predict {
|
| 56 |
+
proxy_pass http://fastapi/predict;
|
| 57 |
+
proxy_set_header Host $host;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
location /predictions {
|
| 61 |
+
proxy_pass http://fastapi/predictions;
|
| 62 |
+
proxy_set_header Host $host;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
location /health {
|
| 66 |
+
proxy_pass http://fastapi/health;
|
| 67 |
+
proxy_set_header Host $host;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
# Streamlit (Catch-all)
|
| 71 |
location / {
|
| 72 |
proxy_pass http://streamlit;
|
| 73 |
proxy_set_header Host $host;
|
|
|
|
| 75 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 76 |
proxy_set_header X-Forwarded-Proto $scheme;
|
| 77 |
|
| 78 |
+
# WebSocket support
|
| 79 |
proxy_http_version 1.1;
|
| 80 |
proxy_set_header Upgrade $http_upgrade;
|
| 81 |
proxy_set_header Connection "upgrade";
|
scripts/start_space.sh
CHANGED
|
@@ -31,6 +31,9 @@ dvc pull models/random_forest_tfidf_gridsearch.pkl.dvc \
|
|
| 31 |
models/tfidf_vectorizer.pkl.dvc \
|
| 32 |
models/label_names.pkl.dvc
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
echo "Starting FastAPI application in background..."
|
| 35 |
uvicorn hopcroft_skill_classification_tool_competition.main:app --host 127.0.0.1 --port 8000 &
|
| 36 |
|
|
@@ -41,6 +44,9 @@ sleep 10
|
|
| 41 |
echo "Starting Nginx reverse proxy..."
|
| 42 |
nginx -c /app/nginx.conf -g "daemon off;" &
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
echo "Starting Streamlit application..."
|
| 45 |
-
export API_BASE_URL="http://
|
| 46 |
streamlit run hopcroft_skill_classification_tool_competition/streamlit_app.py --server.port 8501 --server.address 127.0.0.1
|
|
|
|
| 31 |
models/tfidf_vectorizer.pkl.dvc \
|
| 32 |
models/label_names.pkl.dvc
|
| 33 |
|
| 34 |
+
# Create Nginx temp directories
|
| 35 |
+
mkdir -p /tmp/client_temp /tmp/proxy_temp /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp
|
| 36 |
+
|
| 37 |
echo "Starting FastAPI application in background..."
|
| 38 |
uvicorn hopcroft_skill_classification_tool_competition.main:app --host 127.0.0.1 --port 8000 &
|
| 39 |
|
|
|
|
| 44 |
echo "Starting Nginx reverse proxy..."
|
| 45 |
nginx -c /app/nginx.conf -g "daemon off;" &
|
| 46 |
|
| 47 |
+
echo "Waiting for Nginx to initialize..."
|
| 48 |
+
sleep 2
|
| 49 |
+
|
| 50 |
echo "Starting Streamlit application..."
|
| 51 |
+
export API_BASE_URL="http://127.0.0.1:8000"
|
| 52 |
streamlit run hopcroft_skill_classification_tool_competition/streamlit_app.py --server.port 8501 --server.address 127.0.0.1
|