# Use an official Python runtime as a parent image FROM python:3.9-slim # Set the working directory in the container WORKDIR /app # Install system dependencies (if any are needed beyond standard Python) # For a basic Streamlit app with 'requests', these might not all be strictly necessary, # but they are common for many Python projects and good to have. RUN apt-get update && apt-get install -y \ build-essential \ curl \ software-properties-common \ git \ && rm -rf /var/lib/apt/lists/* # Copy the requirements file into the container at /app COPY requirements.txt ./ # Install any needed packages specified in requirements.txt # Use --no-cache-dir to reduce image size RUN pip install --no-cache-dir -r requirements.txt # Copy your application's main Python file into the container at /app # IMPORTANT: Replace 'streamlit_app.py' if your file is named differently (e.g., 'app.py') COPY streamlit_app.py ./ # (Optional) If you are using Streamlit secrets and have a .streamlit folder: # COPY .streamlit/ ./.streamlit/ # Make port 7860 available to the world outside this container # (Hugging Face Spaces typically uses 7860 for Streamlit, but 8501 is Streamlit's default. # It's best to match what HF expects if you don't override it in Space settings) # Let's stick to 7860 as per common HF practice for now. If you specifically set your Space # to use 8501, then change this and the CMD port. EXPOSE 7860 # Define a health check for the container (optional but good practice for Spaces) # Streamlit has a health endpoint. HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/_stcore/health || exit 1 # Run streamlit_app.py when the container launches # The command uses 0.0.0.0 to bind to all network interfaces # The port should match the EXPOSEd port. ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.headless=true", "--server.address=0.0.0.0"]