File size: 3,091 Bytes
ac86214
3863641
b916cdf
76ab7a4
4dfa41d
ac86214
b916cdf
 
ac86214
b916cdf
 
ac86214
ae3da12
b916cdf
 
ac86214
 
e733937
0d2a979
1828ec1
 
 
 
 
 
 
 
 
0d2a979
76ab7a4
e733937
 
 
76ab7a4
e733937
 
76ab7a4
 
 
e733937
 
 
 
 
 
 
 
 
76ab7a4
e733937
 
 
 
 
 
 
76ab7a4
 
e733937
 
76ab7a4
e733937
 
 
 
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
# 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 startup script using uvicorn like the working version
RUN echo '#!/bin/bash' > start_hf_spaces.sh && \
    echo 'set -e' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo 'echo "πŸš€ Starting Neural OS for HF Spaces with uvicorn"' >> start_hf_spaces.sh && \
    echo 'echo "===================================="' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo '# Start dispatcher directly with uvicorn' >> start_hf_spaces.sh && \
    echo 'echo "🎯 Starting dispatcher with uvicorn..."' >> start_hf_spaces.sh && \
    echo 'uvicorn dispatcher:app --host 0.0.0.0 --port 7860 > dispatcher.log 2>&1 &' >> start_hf_spaces.sh && \
    echo 'DISPATCHER_PID=$!' >> start_hf_spaces.sh && \
    echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo '# Wait for dispatcher to start' >> start_hf_spaces.sh && \
    echo 'echo "⏳ Waiting for dispatcher to initialize..."' >> start_hf_spaces.sh && \
    echo 'sleep 5' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo '# Start worker' >> start_hf_spaces.sh && \
    echo 'echo "πŸ”§ Starting worker..."' >> start_hf_spaces.sh && \
    echo 'python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &' >> start_hf_spaces.sh && \
    echo 'WORKER_PID=$!' >> start_hf_spaces.sh && \
    echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo '# Wait for worker to initialize' >> start_hf_spaces.sh && \
    echo 'echo "⏳ Waiting for worker to initialize..."' >> start_hf_spaces.sh && \
    echo 'sleep 30' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo 'echo "βœ… System ready!"' >> start_hf_spaces.sh && \
    echo 'echo "🌍 Web interface: http://localhost:7860"' >> start_hf_spaces.sh && \
    echo '' >> start_hf_spaces.sh && \
    echo '# Keep running' >> start_hf_spaces.sh && \
    echo 'tail -f dispatcher.log worker.log &' >> start_hf_spaces.sh && \
    echo 'wait $DISPATCHER_PID' >> start_hf_spaces.sh && \
    chmod +x start_hf_spaces.sh

CMD ["bash", "start_hf_spaces.sh"]