File size: 2,608 Bytes
9544071 9f788bf 72143fc 9544071 7206754 a3df053 438e9d6 4d30ffa 438e9d6 7206754 11d34ef a3df053 bf63ed9 f1ffcb6 9544071 9eb1dec b346950 9eb1dec bf63ed9 9544071 f460fb4 438e9d6 a3df053 9544071 f460fb4 b75e6f3 879d729 72d8122 f1ffcb6 72d8122 bf63ed9 f1ffcb6 72d8122 bf63ed9 438e9d6 bf63ed9 f460fb4 438e9d6 b346950 9544071 bf63ed9 9544071 9c24033 438e9d6 9c24033 9544071 a3df053 4f9546f 438e9d6 4f9546f b346950 |
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 |
# Use an official Python runtime as a parent image
FROM python:3.11.5-bookworm
# The next few lines come from here: https://huggingface.co/docs/hub/spaces-sdks-docker#permissions
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user
USER user
# Clone aerospace-chatbot github repository
USER root
WORKDIR /clonedir
RUN apt-get update && \
apt-get install -y git
RUN git clone --depth 1 https://github.com/dan-s-mueller/aerospace_chatbot.git .
# Set home to the user's home directory
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME
# Create directories for the app code to be copied into
RUN mkdir $HOME/app
RUN mkdir $HOME/src
RUN mkdir $HOME/data
RUN mkdir $HOME/config
# Check if /data directory exists, if not create a local db directory. Hugging face spaces has it by default, but not local docker.
RUN if [ ! -d "/data" ]; then \
mkdir $HOME/db; \
fi
# Install Poetry
RUN pip3 install poetry==1.7.1
# Copy poetry files from repo into home
RUN cp /clonedir/pyproject.toml /clonedir/poetry.lock* $HOME
RUN chown user:user $HOME/pyproject.toml $HOME/poetry.lock*
# Disable virtual environments creation by Poetry as the Docker container itself is an isolated environment
RUN poetry config virtualenvs.in-project true
# Set the name of the virtual environment
RUN poetry config virtualenvs.path $HOME/.venv
# Set environment variables
ENV PATH="$HOME/.venv/bin:$PATH"
# Install dependencies using Poetry
RUN poetry install --no-root
# Copy the rest of the repo into home
RUN cp -R /clonedir/src /clonedir/data /clonedir/config /clonedir/app $HOME
RUN chown -R user:user $HOME/src $HOME/data $HOME/config $HOME/db
# Expose the port Streamlit runs on
EXPOSE 8501
# The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working. Your container needs to listen to Streamlit’s (default) port 8501:
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
# Update working directory to be consistent with where Start.py is
WORKDIR $HOME/app
# An ENTRYPOINT allows you to configure a container that will run as an executable. Here, it also contains the entire streamlit run command for your app, so you don’t have to call it from the command line
ENTRYPOINT ["streamlit", "run", "Home.py", "--server.port=8501", "--server.address=0.0.0.0"]
# To run locally
# docker build -t ams-chatbot .
# docker run -p 8501:8501 ams-chatbot
# To run remotely from hugging face spaces
# docker run -it -p 7860:7860 --platform=linux/amd64 \
# registry.hf.space/ai-aerospace-aerospace-chatbots:latest |