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