Spaces:
Runtime error
Runtime error
da03
commited on
Commit
Β·
e733937
1
Parent(s):
ba65ca0
- Dockerfile +38 -142
- static/index.html +3 -2
Dockerfile
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
# Use the official Python 3.9 image
|
| 2 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
| 3 |
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 curl nginx sudo -y
|
| 6 |
|
| 7 |
# Set the working directory to /code
|
| 8 |
WORKDIR /code
|
|
@@ -11,147 +10,12 @@ WORKDIR /code
|
|
| 11 |
COPY ./requirements.txt /code/requirements.txt
|
| 12 |
|
| 13 |
# Install requirements.txt
|
| 14 |
-
|
| 15 |
RUN pip install pip==24.0
|
| 16 |
-
|
| 17 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 18 |
|
| 19 |
# Set up a new user named "user" with user ID 1000
|
| 20 |
RUN useradd -m -u 1000 user
|
| 21 |
-
|
| 22 |
-
# Create nginx configuration for WebSocket support using echo commands
|
| 23 |
-
RUN echo 'server {' > /etc/nginx/sites-available/default && \
|
| 24 |
-
echo ' listen 7860;' >> /etc/nginx/sites-available/default && \
|
| 25 |
-
echo ' server_name _;' >> /etc/nginx/sites-available/default && \
|
| 26 |
-
echo '' >> /etc/nginx/sites-available/default && \
|
| 27 |
-
echo ' # WebSocket support' >> /etc/nginx/sites-available/default && \
|
| 28 |
-
echo ' location /ws {' >> /etc/nginx/sites-available/default && \
|
| 29 |
-
echo ' proxy_pass http://localhost:8080/ws;' >> /etc/nginx/sites-available/default && \
|
| 30 |
-
echo ' proxy_http_version 1.1;' >> /etc/nginx/sites-available/default && \
|
| 31 |
-
echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/sites-available/default && \
|
| 32 |
-
echo ' proxy_set_header Connection "upgrade";' >> /etc/nginx/sites-available/default && \
|
| 33 |
-
echo ' proxy_set_header Host $host;' >> /etc/nginx/sites-available/default && \
|
| 34 |
-
echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/default && \
|
| 35 |
-
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/default && \
|
| 36 |
-
echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/default && \
|
| 37 |
-
echo ' proxy_read_timeout 86400;' >> /etc/nginx/sites-available/default && \
|
| 38 |
-
echo ' }' >> /etc/nginx/sites-available/default && \
|
| 39 |
-
echo '' >> /etc/nginx/sites-available/default && \
|
| 40 |
-
echo ' # Regular HTTP requests' >> /etc/nginx/sites-available/default && \
|
| 41 |
-
echo ' location / {' >> /etc/nginx/sites-available/default && \
|
| 42 |
-
echo ' proxy_pass http://localhost:8080;' >> /etc/nginx/sites-available/default && \
|
| 43 |
-
echo ' proxy_set_header Host $host;' >> /etc/nginx/sites-available/default && \
|
| 44 |
-
echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/default && \
|
| 45 |
-
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/default && \
|
| 46 |
-
echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/default && \
|
| 47 |
-
echo ' }' >> /etc/nginx/sites-available/default && \
|
| 48 |
-
echo '}' >> /etc/nginx/sites-available/default
|
| 49 |
-
|
| 50 |
-
# Create directories for nginx
|
| 51 |
-
RUN mkdir -p /run/nginx && chmod 755 /run/nginx
|
| 52 |
-
|
| 53 |
-
# Give user sudo permissions for nginx
|
| 54 |
-
RUN echo "user ALL=(ALL) NOPASSWD: /usr/sbin/nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -s quit" >> /etc/sudoers
|
| 55 |
-
|
| 56 |
-
# Create a startup script that runs as root initially (while we're still root)
|
| 57 |
-
RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
|
| 58 |
-
echo 'set -e' >> /start_hf_spaces.sh && \
|
| 59 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 60 |
-
echo 'echo "π Starting Neural OS for HF Spaces with nginx proxy"' >> /start_hf_spaces.sh && \
|
| 61 |
-
echo 'echo "===================================="' >> /start_hf_spaces.sh && \
|
| 62 |
-
echo 'echo "π Current directory: $(pwd)"' >> /start_hf_spaces.sh && \
|
| 63 |
-
echo 'cd /home/user/app' >> /start_hf_spaces.sh && \
|
| 64 |
-
echo 'echo "π Files in current directory:"' >> /start_hf_spaces.sh && \
|
| 65 |
-
echo 'ls -la' >> /start_hf_spaces.sh && \
|
| 66 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 67 |
-
echo '# Check if required files exist' >> /start_hf_spaces.sh && \
|
| 68 |
-
echo 'if [[ ! -f "dispatcher.py" ]]; then' >> /start_hf_spaces.sh && \
|
| 69 |
-
echo ' echo "β Error: dispatcher.py not found"' >> /start_hf_spaces.sh && \
|
| 70 |
-
echo ' exit 1' >> /start_hf_spaces.sh && \
|
| 71 |
-
echo 'fi' >> /start_hf_spaces.sh && \
|
| 72 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 73 |
-
echo 'if [[ ! -f "worker.py" ]]; then' >> /start_hf_spaces.sh && \
|
| 74 |
-
echo ' echo "β Error: worker.py not found"' >> /start_hf_spaces.sh && \
|
| 75 |
-
echo ' exit 1' >> /start_hf_spaces.sh && \
|
| 76 |
-
echo 'fi' >> /start_hf_spaces.sh && \
|
| 77 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 78 |
-
echo 'if [[ ! -f "static/index.html" ]]; then' >> /start_hf_spaces.sh && \
|
| 79 |
-
echo ' echo "β Error: static/index.html not found"' >> /start_hf_spaces.sh && \
|
| 80 |
-
echo ' exit 1' >> /start_hf_spaces.sh && \
|
| 81 |
-
echo 'fi' >> /start_hf_spaces.sh && \
|
| 82 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 83 |
-
echo 'echo "β
All required files found"' >> /start_hf_spaces.sh && \
|
| 84 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 85 |
-
echo '# Start nginx as root' >> /start_hf_spaces.sh && \
|
| 86 |
-
echo 'echo "π Starting nginx proxy..."' >> /start_hf_spaces.sh && \
|
| 87 |
-
echo 'mkdir -p /run/nginx' >> /start_hf_spaces.sh && \
|
| 88 |
-
echo 'nginx -t && nginx' >> /start_hf_spaces.sh && \
|
| 89 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 90 |
-
echo '# Start dispatcher as user using runuser' >> /start_hf_spaces.sh && \
|
| 91 |
-
echo 'echo "π― Starting dispatcher..."' >> /start_hf_spaces.sh && \
|
| 92 |
-
echo 'cd /home/user/app' >> /start_hf_spaces.sh && \
|
| 93 |
-
echo 'runuser -l user -c "cd /home/user/app && python dispatcher.py --port 8080" > dispatcher.log 2>&1 &' >> /start_hf_spaces.sh && \
|
| 94 |
-
echo 'DISPATCHER_PID=$!' >> /start_hf_spaces.sh && \
|
| 95 |
-
echo 'echo "π Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
|
| 96 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 97 |
-
echo '# Wait for dispatcher to start' >> /start_hf_spaces.sh && \
|
| 98 |
-
echo 'echo "β³ Waiting for dispatcher to initialize..."' >> /start_hf_spaces.sh && \
|
| 99 |
-
echo 'sleep 5' >> /start_hf_spaces.sh && \
|
| 100 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 101 |
-
echo '# Test if dispatcher is responding' >> /start_hf_spaces.sh && \
|
| 102 |
-
echo 'echo "π Testing dispatcher health (via nginx)..."' >> /start_hf_spaces.sh && \
|
| 103 |
-
echo 'curl -f http://localhost:7860/ > /dev/null 2>&1' >> /start_hf_spaces.sh && \
|
| 104 |
-
echo 'if [ $? -eq 0 ]; then' >> /start_hf_spaces.sh && \
|
| 105 |
-
echo ' echo "β
Nginx proxy is working"' >> /start_hf_spaces.sh && \
|
| 106 |
-
echo 'else' >> /start_hf_spaces.sh && \
|
| 107 |
-
echo ' echo "β οΈ Nginx proxy test failed"' >> /start_hf_spaces.sh && \
|
| 108 |
-
echo 'fi' >> /start_hf_spaces.sh && \
|
| 109 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 110 |
-
echo '# Start worker as user using runuser' >> /start_hf_spaces.sh && \
|
| 111 |
-
echo 'echo "π§ Starting worker..."' >> /start_hf_spaces.sh && \
|
| 112 |
-
echo 'runuser -l user -c "cd /home/user/app && python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:8080" > worker.log 2>&1 &' >> /start_hf_spaces.sh && \
|
| 113 |
-
echo 'WORKER_PID=$!' >> /start_hf_spaces.sh && \
|
| 114 |
-
echo 'echo "π Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
|
| 115 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 116 |
-
echo '# Wait for worker to initialize' >> /start_hf_spaces.sh && \
|
| 117 |
-
echo 'echo "β³ Waiting for worker to initialize..."' >> /start_hf_spaces.sh && \
|
| 118 |
-
echo 'sleep 30' >> /start_hf_spaces.sh && \
|
| 119 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 120 |
-
echo '# Check if worker is running' >> /start_hf_spaces.sh && \
|
| 121 |
-
echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> /start_hf_spaces.sh && \
|
| 122 |
-
echo ' echo "β Worker failed to start"' >> /start_hf_spaces.sh && \
|
| 123 |
-
echo ' echo "π Worker log:"' >> /start_hf_spaces.sh && \
|
| 124 |
-
echo ' tail -n 50 worker.log' >> /start_hf_spaces.sh && \
|
| 125 |
-
echo ' echo "π Dispatcher log:"' >> /start_hf_spaces.sh && \
|
| 126 |
-
echo ' tail -n 50 dispatcher.log' >> /start_hf_spaces.sh && \
|
| 127 |
-
echo ' exit 1' >> /start_hf_spaces.sh && \
|
| 128 |
-
echo 'fi' >> /start_hf_spaces.sh && \
|
| 129 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 130 |
-
echo 'echo "β
System ready!"' >> /start_hf_spaces.sh && \
|
| 131 |
-
echo 'echo "π Web interface: http://localhost:7860 (via nginx)"' >> /start_hf_spaces.sh && \
|
| 132 |
-
echo 'echo "π― Dispatcher: http://localhost:8080 (direct)"' >> /start_hf_spaces.sh && \
|
| 133 |
-
echo 'echo "π Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
|
| 134 |
-
echo 'echo "π Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
|
| 135 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 136 |
-
echo '# Function to cleanup' >> /start_hf_spaces.sh && \
|
| 137 |
-
echo 'cleanup() {' >> /start_hf_spaces.sh && \
|
| 138 |
-
echo ' echo "π Shutting down..."' >> /start_hf_spaces.sh && \
|
| 139 |
-
echo ' kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \
|
| 140 |
-
echo ' nginx -s quit 2>/dev/null || true' >> /start_hf_spaces.sh && \
|
| 141 |
-
echo ' exit 0' >> /start_hf_spaces.sh && \
|
| 142 |
-
echo '}' >> /start_hf_spaces.sh && \
|
| 143 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 144 |
-
echo 'trap cleanup SIGINT SIGTERM' >> /start_hf_spaces.sh && \
|
| 145 |
-
echo '' >> /start_hf_spaces.sh && \
|
| 146 |
-
echo '# Keep the script running' >> /start_hf_spaces.sh && \
|
| 147 |
-
echo 'echo "π Following logs (Ctrl+C to stop):"' >> /start_hf_spaces.sh && \
|
| 148 |
-
echo 'tail -f dispatcher.log worker.log &' >> /start_hf_spaces.sh && \
|
| 149 |
-
echo 'TAIL_PID=$!' >> /start_hf_spaces.sh && \
|
| 150 |
-
echo 'wait $DISPATCHER_PID' >> /start_hf_spaces.sh && \
|
| 151 |
-
echo 'kill $TAIL_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \
|
| 152 |
-
chmod +x /start_hf_spaces.sh
|
| 153 |
-
|
| 154 |
-
# Switch to user and copy files
|
| 155 |
USER user
|
| 156 |
# Set home to the user's home directory
|
| 157 |
ENV HOME=/home/user \
|
|
@@ -163,7 +27,39 @@ WORKDIR $HOME/app
|
|
| 163 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 164 |
COPY --chown=user . $HOME/app
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Use the official Python 3.9 image
|
| 2 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
| 3 |
|
| 4 |
+
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 curl -y
|
|
|
|
| 5 |
|
| 6 |
# Set the working directory to /code
|
| 7 |
WORKDIR /code
|
|
|
|
| 10 |
COPY ./requirements.txt /code/requirements.txt
|
| 11 |
|
| 12 |
# Install requirements.txt
|
|
|
|
| 13 |
RUN pip install pip==24.0
|
|
|
|
| 14 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 15 |
|
| 16 |
# Set up a new user named "user" with user ID 1000
|
| 17 |
RUN useradd -m -u 1000 user
|
| 18 |
+
# Switch to the "user" user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
USER user
|
| 20 |
# Set home to the user's home directory
|
| 21 |
ENV HOME=/home/user \
|
|
|
|
| 27 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 28 |
COPY --chown=user . $HOME/app
|
| 29 |
|
| 30 |
+
# Create a simple startup script
|
| 31 |
+
RUN echo '#!/bin/bash' > start_hf_spaces.sh && \
|
| 32 |
+
echo 'set -e' >> start_hf_spaces.sh && \
|
| 33 |
+
echo '' >> start_hf_spaces.sh && \
|
| 34 |
+
echo 'echo "π Starting Neural OS for HF Spaces (Simple Version)"' >> start_hf_spaces.sh && \
|
| 35 |
+
echo 'echo "===================================="' >> start_hf_spaces.sh && \
|
| 36 |
+
echo '' >> start_hf_spaces.sh && \
|
| 37 |
+
echo '# Start dispatcher' >> start_hf_spaces.sh && \
|
| 38 |
+
echo 'echo "π― Starting dispatcher..."' >> start_hf_spaces.sh && \
|
| 39 |
+
echo 'python dispatcher.py --port 7860 > dispatcher.log 2>&1 &' >> start_hf_spaces.sh && \
|
| 40 |
+
echo 'DISPATCHER_PID=$!' >> start_hf_spaces.sh && \
|
| 41 |
+
echo 'echo "π Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
|
| 42 |
+
echo '' >> start_hf_spaces.sh && \
|
| 43 |
+
echo '# Wait for dispatcher to start' >> start_hf_spaces.sh && \
|
| 44 |
+
echo 'echo "β³ Waiting for dispatcher to initialize..."' >> start_hf_spaces.sh && \
|
| 45 |
+
echo 'sleep 5' >> start_hf_spaces.sh && \
|
| 46 |
+
echo '' >> start_hf_spaces.sh && \
|
| 47 |
+
echo '# Start worker' >> start_hf_spaces.sh && \
|
| 48 |
+
echo 'echo "π§ Starting worker..."' >> start_hf_spaces.sh && \
|
| 49 |
+
echo 'python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &' >> start_hf_spaces.sh && \
|
| 50 |
+
echo 'WORKER_PID=$!' >> start_hf_spaces.sh && \
|
| 51 |
+
echo 'echo "π Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
|
| 52 |
+
echo '' >> start_hf_spaces.sh && \
|
| 53 |
+
echo '# Wait for worker to initialize' >> start_hf_spaces.sh && \
|
| 54 |
+
echo 'echo "β³ Waiting for worker to initialize..."' >> start_hf_spaces.sh && \
|
| 55 |
+
echo 'sleep 30' >> start_hf_spaces.sh && \
|
| 56 |
+
echo '' >> start_hf_spaces.sh && \
|
| 57 |
+
echo 'echo "β
System ready!"' >> start_hf_spaces.sh && \
|
| 58 |
+
echo 'echo "π Web interface: http://localhost:7860"' >> start_hf_spaces.sh && \
|
| 59 |
+
echo '' >> start_hf_spaces.sh && \
|
| 60 |
+
echo '# Keep running' >> start_hf_spaces.sh && \
|
| 61 |
+
echo 'tail -f dispatcher.log worker.log &' >> start_hf_spaces.sh && \
|
| 62 |
+
echo 'wait $DISPATCHER_PID' >> start_hf_spaces.sh && \
|
| 63 |
+
chmod +x start_hf_spaces.sh
|
| 64 |
+
|
| 65 |
+
CMD ["bash", "start_hf_spaces.sh"]
|
static/index.html
CHANGED
|
@@ -187,7 +187,8 @@
|
|
| 187 |
|
| 188 |
function connect() {
|
| 189 |
console.log("connect() function called - creating new WebSocket connection");
|
| 190 |
-
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
|
|
| 191 |
socket = new WebSocket(`${protocol}//${window.location.host}/ws`);
|
| 192 |
|
| 193 |
socket.onopen = function(event) {
|
|
@@ -1117,4 +1118,4 @@
|
|
| 1117 |
<!-- Bootstrap JS (optional) -->
|
| 1118 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
| 1119 |
</body>
|
| 1120 |
-
</html>
|
|
|
|
| 187 |
|
| 188 |
function connect() {
|
| 189 |
console.log("connect() function called - creating new WebSocket connection");
|
| 190 |
+
//const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
| 191 |
+
const protocol = 'ws:';
|
| 192 |
socket = new WebSocket(`${protocol}//${window.location.host}/ws`);
|
| 193 |
|
| 194 |
socket.onopen = function(event) {
|
|
|
|
| 1118 |
<!-- Bootstrap JS (optional) -->
|
| 1119 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
| 1120 |
</body>
|
| 1121 |
+
</html>
|