subbu123456 commited on
Commit
e3fbb92
·
verified ·
1 Parent(s): 0c96be1

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +38 -0
  2. docker-compose.yml +15 -0
Dockerfile ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Create a non-root user
13
+ RUN useradd -m -u 1000 appuser
14
+
15
+ # Copy requirements first to leverage Docker cache
16
+ COPY requirements.txt .
17
+
18
+ # Install Python dependencies
19
+ RUN pip install --no-cache-dir -r requirements.txt
20
+
21
+ # Create necessary directories and set permissions
22
+ RUN mkdir -p /app/saved_models /app/tokenizer /app/predictions /app/.cache \
23
+ && chown -R appuser:appuser /app
24
+
25
+ # Switch to non-root user
26
+ USER appuser
27
+
28
+ # Copy the application code
29
+ COPY --chown=appuser:appuser . .
30
+
31
+ # Download the BERT tokenizer
32
+ RUN python -c "from transformers import BertTokenizer; BertTokenizer.from_pretrained('bert-base-uncased', cache_dir='/app/.cache')"
33
+
34
+ # Expose the port the app runs on (7860 for Hugging Face Spaces)
35
+ EXPOSE 7860
36
+
37
+ # Command to run the application
38
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
docker-compose.yml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ bert-api:
5
+ build: .
6
+ ports:
7
+ - "8000:8000"
8
+ volumes:
9
+ - ../saved_models:/app/saved_models
10
+ - ../tokenizer:/app/tokenizer
11
+ - ../predictions:/app/predictions
12
+ - ../label_encoders.pkl:/app/label_encoders.pkl
13
+ environment:
14
+ - PYTHONUNBUFFERED=1
15
+ restart: unless-stopped