agent_1 / Dockerfile
Entz's picture
Upload 2 files
9fbe5ee verified
# Use an official Python runtime matching Hugging Face's environment
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies (curl for Ollama, git for pip)
RUN apt-get update && apt-get install -y \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh
# Pre-pull llama3 during build to avoid runtime delays
RUN ollama serve & \
until curl -s http://localhost:11434 > /dev/null; do \
echo 'Waiting for Ollama...'; sleep 1; \
done && \
ollama pull llama3 && \
echo "Model pulled successfully" || echo "Model pull failed" && \
ollama list > /app/models.txt && \
cat /app/models.txt
# Copy requirements file first (optimization for caching)
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy only the app file
COPY app.py .
# Expose the port Hugging Face Spaces expects
EXPOSE 7860
# Set environment variables for Ollama
ENV OLLAMA_HOST=0.0.0.0
ENV OLLAMA_PORT=11434
# Start Ollama and Streamlit with a more robust wait
CMD bash -c "ollama serve & sleep 5 && until curl -s http://localhost:11434 > /dev/null; do echo 'Waiting for Ollama...'; sleep 1; done && streamlit run app.py --server.port 7860 --server.address 0.0.0.0"