da03 commited on
Commit
d83ec2c
Β·
1 Parent(s): 0bd83b0
Files changed (1) hide show
  1. 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 -y
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
- COPY --chown=user <<EOF $HOME/app/start_hf_spaces.sh
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
- # Wait for dispatcher to start
52
- sleep 3
53
-
54
- # Start single worker (HF Spaces typically has 1 GPU or CPU)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 \$DISPATCHER_PID \$WORKER_PID 2>/dev/null || true
70
  exit 0
71
  }
72
 
73
  trap cleanup SIGINT SIGTERM
74
 
 
 
 
 
 
75
  # Wait for dispatcher (main process)
76
- wait \$DISPATCHER_PID
 
 
 
77
  EOF
78
 
79
- RUN chmod +x $HOME/app/start_hf_spaces.sh
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"]