thelip commited on
Commit
2a0f699
·
verified ·
1 Parent(s): ce47731

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +41 -0
Dockerfile ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1. Base Image: Use a slim Python image
2
+ FROM python:3.10-slim
3
+
4
+ # 2. Set Environment Variables (Optional but good practice)
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PIP_NO_CACHE_DIR=off \
7
+ PIP_DISABLE_PIP_VERSION_CHECK=on \
8
+ # Set path for Hugging Face model cache (inside the container)
9
+ HF_HOME="/app/huggingface_cache" \
10
+ TRANSFORMERS_CACHE="/app/huggingface_cache/transformers" \
11
+ # If you need to use a Hugging Face token (e.g., for gated models, though Gemma isn't)
12
+ # HUGGING_FACE_HUB_TOKEN="your_hf_token_here" # Best to pass this at runtime or via secrets
13
+
14
+ # 3. Set Working Directory
15
+ WORKDIR /app
16
+
17
+ # 4. Copy requirements file and install dependencies
18
+ # This is done before copying the rest of the app to leverage Docker layer caching.
19
+ COPY requirements.txt .
20
+ RUN apt-get update && apt-get install -y --no-install-recommends \
21
+ build-essential \
22
+ && rm -rf /var/lib/apt/lists/* # build-essential might be needed by some torch/scipy deps
23
+ RUN pip install --no-cache-dir -r requirements.txt
24
+
25
+ # 5. Copy the rest of the application code
26
+ COPY app.py .
27
+
28
+ # 6. Create the cache directory and set permissions (if needed)
29
+ # The user running the pip install command will own the HF_HOME path.
30
+ # If running as non-root later, ensure permissions.
31
+ RUN mkdir -p $HF_HOME && chmod -R 777 $HF_HOME
32
+ # Note: chmod 777 is very permissive, for production, use a more specific user/group.
33
+ # For Hugging Face Spaces, this is generally fine.
34
+
35
+ # 7. Expose the port the app runs on
36
+ EXPOSE 8000
37
+
38
+ # 8. Command to run the application
39
+ # The model will be downloaded on the first run if not already cached.
40
+ # For Hugging Face Spaces, this download happens during the build process.
41
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]