N-I-M-I commited on
Commit
d974f7d
·
verified ·
1 Parent(s): 78b18d7

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -16
Dockerfile CHANGED
@@ -1,31 +1,42 @@
1
- # Use an official Python runtime as a parent image
2
  FROM python:3.9-slim
3
 
4
- # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Install system dependencies for OpenCV and other potential needs
8
- RUN apt-get update && apt-get install -y \
 
 
 
 
 
 
9
  build-essential \
10
- libgl1-mesa-glx \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Copy the requirements file into the container
14
  COPY requirements.txt .
15
 
16
- # Install any needed packages specified in requirements.txt
17
- RUN pip install --no-cache-dir -r requirements.txt
18
- RUN pip install --no-cache-dir gunicorn
 
 
19
 
20
- # Copy the rest of the application code into the container
21
  COPY . .
22
 
23
- # Create directory for data if it doesn't exist
24
- RUN mkdir -p data/cifar-10-batches-py
25
 
26
- # Expose the port the app runs on
27
  EXPOSE 7860
28
 
29
- # Command to run the application using gunicorn for production
30
- # We use 7860 because it's the default port for Hugging Face Spaces
31
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
 
 
 
 
1
+ # Use Python 3.9 slim image
2
  FROM python:3.9-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
+ # Set environment variables
8
+ ENV PYTHONUNBUFFERED=1 \
9
+ PYTHONDONTWRITEBYTECODE=1 \
10
+ PIP_NO_CACHE_DIR=1 \
11
+ PIP_DISABLE_PIP_VERSION_CHECK=1
12
+
13
+ # Install system dependencies
14
+ RUN apt-get update && apt-get install -y --no-install-recommends \
15
  build-essential \
16
+ libgomp1 \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
+ # Copy requirements first for better caching
20
  COPY requirements.txt .
21
 
22
+ # Install Python dependencies
23
+ RUN pip install --no-cache-dir --upgrade pip && \
24
+ pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu && \
25
+ pip install --no-cache-dir -r requirements.txt && \
26
+ pip install --no-cache-dir gunicorn
27
 
28
+ # Copy application code
29
  COPY . .
30
 
31
+ # Create necessary directories
32
+ RUN mkdir -p data checkpoints plots
33
 
34
+ # Expose port
35
  EXPOSE 7860
36
 
37
+ # Health check
38
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
39
+ CMD python -c "import requests; requests.get('http://localhost:7860')" || exit 1
40
+
41
+ # Run the application
42
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "120", "app:app"]