DaCrow13
commited on
Commit
·
9e1edfd
1
Parent(s):
d2fd1ac
feat: Add Nginx reverse proxy configuration and a new startup script to serve FastAPI and Streamlit applications.
Browse files- Dockerfile +1 -0
- README.md +1 -0
- nginx.conf +59 -0
- scripts/start_space.sh +6 -3
Dockerfile
CHANGED
|
@@ -11,6 +11,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
| 11 |
RUN apt-get update && apt-get install -y \
|
| 12 |
git \
|
| 13 |
dos2unix \
|
|
|
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
# Create a non-root user
|
|
|
|
| 11 |
RUN apt-get update && apt-get install -y \
|
| 12 |
git \
|
| 13 |
dos2unix \
|
| 14 |
+
nginx \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
# Create a non-root user
|
README.md
CHANGED
|
@@ -5,6 +5,7 @@ colorFrom: blue
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
# Hopcroft_Skill-Classification-Tool-Competition
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
| 8 |
+
api_docs_url: /docs
|
| 9 |
---
|
| 10 |
|
| 11 |
# Hopcroft_Skill-Classification-Tool-Competition
|
nginx.conf
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
worker_processes 1;
|
| 2 |
+
pid /tmp/nginx.pid;
|
| 3 |
+
error_log /tmp/nginx.error.log;
|
| 4 |
+
|
| 5 |
+
events {
|
| 6 |
+
worker_connections 1024;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
http {
|
| 10 |
+
include /etc/nginx/mime.types;
|
| 11 |
+
default_type application/octet-stream;
|
| 12 |
+
|
| 13 |
+
access_log /tmp/nginx.access.log;
|
| 14 |
+
client_body_temp_path /tmp/client_temp;
|
| 15 |
+
proxy_temp_path /tmp/proxy_temp;
|
| 16 |
+
fastcgi_temp_path /tmp/fastcgi_temp;
|
| 17 |
+
uwsgi_temp_path /tmp/uwsgi_temp;
|
| 18 |
+
scgi_temp_path /tmp/scgi_temp;
|
| 19 |
+
|
| 20 |
+
sendfile on;
|
| 21 |
+
keepalive_timeout 65;
|
| 22 |
+
|
| 23 |
+
upstream streamlit {
|
| 24 |
+
server 127.0.0.1:8501;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
upstream fastapi {
|
| 28 |
+
server 127.0.0.1:8000;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
server {
|
| 32 |
+
listen 7860;
|
| 33 |
+
server_name localhost;
|
| 34 |
+
|
| 35 |
+
# FastAPI endpoints
|
| 36 |
+
location ~ ^/(docs|redoc|openapi.json|predict|predictions|health) {
|
| 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 |
+
# Streamlit (Default)
|
| 45 |
+
location / {
|
| 46 |
+
proxy_pass http://streamlit;
|
| 47 |
+
proxy_set_header Host $host;
|
| 48 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 49 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 50 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 51 |
+
|
| 52 |
+
# Streamlit-specific settings for WebSocket
|
| 53 |
+
proxy_http_version 1.1;
|
| 54 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 55 |
+
proxy_set_header Connection "upgrade";
|
| 56 |
+
proxy_read_timeout 86400;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
scripts/start_space.sh
CHANGED
|
@@ -32,12 +32,15 @@ dvc pull models/random_forest_tfidf_gridsearch.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
|
| 36 |
|
| 37 |
# Wait for API to start
|
| 38 |
echo "Waiting for API to start..."
|
| 39 |
sleep 10
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
echo "Starting Streamlit application..."
|
| 42 |
-
export API_BASE_URL="http://localhost:8000
|
| 43 |
-
streamlit run hopcroft_skill_classification_tool_competition/streamlit_app.py --server.port
|
|
|
|
| 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 |
|
| 37 |
# Wait for API to start
|
| 38 |
echo "Waiting for API to start..."
|
| 39 |
sleep 10
|
| 40 |
|
| 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://localhost:7860" # Use the proxy URL for the GUI if needed, or stick to 8000
|
| 46 |
+
streamlit run hopcroft_skill_classification_tool_competition/streamlit_app.py --server.port 8501 --server.address 127.0.0.1
|