Spaces:
Runtime error
Runtime error
da03
commited on
Commit
Β·
d83ec2c
1
Parent(s):
0bd83b0
- Dockerfile +72 -17
Dockerfile
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
| 3 |
|
| 4 |
|
| 5 |
-
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6
|
| 6 |
|
| 7 |
# Set the working directory to /code
|
| 8 |
WORKDIR /code
|
|
@@ -16,11 +16,6 @@ RUN pip install pip==24.0
|
|
| 16 |
|
| 17 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 18 |
|
| 19 |
-
#RUN git clone https://github.com/da03/latent-diffusion.git
|
| 20 |
-
|
| 21 |
-
# Install latent-diffusion in editable mode
|
| 22 |
-
#RUN pip install -e ./latent-diffusion
|
| 23 |
-
|
| 24 |
# Set up a new user named "user" with user ID 1000
|
| 25 |
RUN useradd -m -u 1000 user
|
| 26 |
# Switch to the "user" user
|
|
@@ -36,46 +31,106 @@ WORKDIR $HOME/app
|
|
| 36 |
COPY --chown=user . $HOME/app
|
| 37 |
|
| 38 |
# Create a startup script for HF Spaces
|
| 39 |
-
|
| 40 |
#!/bin/bash
|
| 41 |
set -e
|
| 42 |
|
| 43 |
echo "π Starting Neural OS for HF Spaces"
|
| 44 |
echo "===================================="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Start dispatcher in background
|
| 47 |
echo "π― Starting dispatcher..."
|
| 48 |
python dispatcher.py --port 7860 > dispatcher.log 2>&1 &
|
| 49 |
-
DISPATCHER_PID
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
echo "π§ Starting worker..."
|
| 56 |
python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &
|
| 57 |
-
WORKER_PID
|
|
|
|
| 58 |
|
| 59 |
# Wait for worker to initialize
|
| 60 |
echo "β³ Waiting for worker to initialize..."
|
| 61 |
sleep 30
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
echo "β
System ready!"
|
| 64 |
echo "π Web interface: http://localhost:7860"
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# Function to cleanup
|
| 67 |
cleanup() {
|
| 68 |
echo "π Shutting down..."
|
| 69 |
-
kill
|
| 70 |
exit 0
|
| 71 |
}
|
| 72 |
|
| 73 |
trap cleanup SIGINT SIGTERM
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Wait for dispatcher (main process)
|
| 76 |
-
wait
|
|
|
|
|
|
|
|
|
|
| 77 |
EOF
|
| 78 |
|
| 79 |
-
RUN chmod +x
|
| 80 |
|
| 81 |
CMD ["bash", "start_hf_spaces.sh"]
|
|
|
|
| 2 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
| 3 |
|
| 4 |
|
| 5 |
+
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 curl -y
|
| 6 |
|
| 7 |
# Set the working directory to /code
|
| 8 |
WORKDIR /code
|
|
|
|
| 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 |
# Switch to the "user" user
|
|
|
|
| 31 |
COPY --chown=user . $HOME/app
|
| 32 |
|
| 33 |
# Create a startup script for HF Spaces
|
| 34 |
+
RUN cat > start_hf_spaces.sh << 'EOF'
|
| 35 |
#!/bin/bash
|
| 36 |
set -e
|
| 37 |
|
| 38 |
echo "π Starting Neural OS for HF Spaces"
|
| 39 |
echo "===================================="
|
| 40 |
+
echo "π Current directory: $(pwd)"
|
| 41 |
+
echo "π Files in current directory:"
|
| 42 |
+
ls -la
|
| 43 |
+
|
| 44 |
+
# Check if required files exist
|
| 45 |
+
if [[ ! -f "dispatcher.py" ]]; then
|
| 46 |
+
echo "β Error: dispatcher.py not found"
|
| 47 |
+
exit 1
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
if [[ ! -f "worker.py" ]]; then
|
| 51 |
+
echo "β Error: worker.py not found"
|
| 52 |
+
exit 1
|
| 53 |
+
fi
|
| 54 |
+
|
| 55 |
+
if [[ ! -f "static/index.html" ]]; then
|
| 56 |
+
echo "β Error: static/index.html not found"
|
| 57 |
+
exit 1
|
| 58 |
+
fi
|
| 59 |
+
|
| 60 |
+
echo "β
All required files found"
|
| 61 |
|
| 62 |
# Start dispatcher in background
|
| 63 |
echo "π― Starting dispatcher..."
|
| 64 |
python dispatcher.py --port 7860 > dispatcher.log 2>&1 &
|
| 65 |
+
DISPATCHER_PID=$!
|
| 66 |
+
echo "π Dispatcher PID: $DISPATCHER_PID"
|
| 67 |
+
|
| 68 |
+
# Wait for dispatcher to start and check if it's running
|
| 69 |
+
echo "β³ Waiting for dispatcher to initialize..."
|
| 70 |
+
sleep 5
|
| 71 |
+
|
| 72 |
+
if ! kill -0 $DISPATCHER_PID 2>/dev/null; then
|
| 73 |
+
echo "β Dispatcher failed to start"
|
| 74 |
+
echo "π Dispatcher log:"
|
| 75 |
+
cat dispatcher.log
|
| 76 |
+
exit 1
|
| 77 |
+
fi
|
| 78 |
+
|
| 79 |
+
# Test if dispatcher is responding
|
| 80 |
+
echo "π Testing dispatcher health..."
|
| 81 |
+
curl -f http://localhost:7860/ > /dev/null 2>&1
|
| 82 |
+
if [ $? -eq 0 ]; then
|
| 83 |
+
echo "β
Dispatcher is responding to HTTP requests"
|
| 84 |
+
else
|
| 85 |
+
echo "β οΈ Dispatcher HTTP test failed, but continuing..."
|
| 86 |
+
fi
|
| 87 |
+
|
| 88 |
+
# Start single worker
|
| 89 |
echo "π§ Starting worker..."
|
| 90 |
python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &
|
| 91 |
+
WORKER_PID=$!
|
| 92 |
+
echo "π Worker PID: $WORKER_PID"
|
| 93 |
|
| 94 |
# Wait for worker to initialize
|
| 95 |
echo "β³ Waiting for worker to initialize..."
|
| 96 |
sleep 30
|
| 97 |
|
| 98 |
+
# Check if worker is still running
|
| 99 |
+
if ! kill -0 $WORKER_PID 2>/dev/null; then
|
| 100 |
+
echo "β Worker failed to start"
|
| 101 |
+
echo "π Worker log:"
|
| 102 |
+
cat worker.log
|
| 103 |
+
echo "π Dispatcher log:"
|
| 104 |
+
cat dispatcher.log
|
| 105 |
+
exit 1
|
| 106 |
+
fi
|
| 107 |
+
|
| 108 |
echo "β
System ready!"
|
| 109 |
echo "π Web interface: http://localhost:7860"
|
| 110 |
+
echo "π Dispatcher PID: $DISPATCHER_PID"
|
| 111 |
+
echo "π Worker PID: $WORKER_PID"
|
| 112 |
|
| 113 |
# Function to cleanup
|
| 114 |
cleanup() {
|
| 115 |
echo "π Shutting down..."
|
| 116 |
+
kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true
|
| 117 |
exit 0
|
| 118 |
}
|
| 119 |
|
| 120 |
trap cleanup SIGINT SIGTERM
|
| 121 |
|
| 122 |
+
# Keep the script running by following the dispatcher log
|
| 123 |
+
echo "π Following dispatcher log (Ctrl+C to stop):"
|
| 124 |
+
tail -f dispatcher.log &
|
| 125 |
+
TAIL_PID=$!
|
| 126 |
+
|
| 127 |
# Wait for dispatcher (main process)
|
| 128 |
+
wait $DISPATCHER_PID
|
| 129 |
+
|
| 130 |
+
# Clean up tail process
|
| 131 |
+
kill $TAIL_PID 2>/dev/null || true
|
| 132 |
EOF
|
| 133 |
|
| 134 |
+
RUN chmod +x start_hf_spaces.sh
|
| 135 |
|
| 136 |
CMD ["bash", "start_hf_spaces.sh"]
|