Commit
·
cc15462
1
Parent(s):
f1d9c38
deploy
Browse files- Dockerfile +2 -16
- services/embedding.py +7 -2
Dockerfile
CHANGED
@@ -1,23 +1,9 @@
|
|
1 |
-
# Use official Python 3.9 image
|
2 |
FROM python:3.10-slim
|
3 |
-
|
4 |
-
# Set working directory
|
5 |
WORKDIR /app
|
6 |
-
|
7 |
-
# Copy requirements file
|
8 |
COPY requirements.txt .
|
9 |
-
|
10 |
-
# Install dependencies
|
11 |
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
-
|
13 |
-
# Create cache directory with proper permissions
|
14 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
15 |
-
|
16 |
-
# Copy application code
|
17 |
-
COPY . .
|
18 |
-
|
19 |
-
# Expose port 8000
|
20 |
EXPOSE 7860
|
21 |
-
|
22 |
-
# Start FastAPI with uvicorn
|
23 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
1 |
FROM python:3.10-slim
|
|
|
|
|
2 |
WORKDIR /app
|
|
|
|
|
3 |
COPY requirements.txt .
|
|
|
|
|
4 |
RUN pip install --no-cache-dir -r requirements.txt
|
5 |
+
# Create and set permissions for cache directory
|
|
|
6 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
7 |
+
COPY app/ .
|
|
|
|
|
|
|
|
|
8 |
EXPOSE 7860
|
|
|
|
|
9 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
services/embedding.py
CHANGED
@@ -5,10 +5,15 @@ from typing import List, Optional
|
|
5 |
import torch
|
6 |
import os
|
7 |
|
8 |
-
#
|
9 |
-
# Set a writable cache directory
|
10 |
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
|
11 |
os.environ["HF_HOME"] = "/app/cache"
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Load model with custom cache directory
|
14 |
model = SentenceTransformer("clip-ViT-B-32")
|
|
|
5 |
import torch
|
6 |
import os
|
7 |
|
8 |
+
# Set multiple environment variables to redirect all caching
|
|
|
9 |
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
|
10 |
os.environ["HF_HOME"] = "/app/cache"
|
11 |
+
os.environ["XDG_CACHE_HOME"] = "/app/cache" # Additional variable for broader compatibility
|
12 |
+
|
13 |
+
# Ensure cache directory exists (redundant with Dockerfile but added for safety)
|
14 |
+
cache_dir = "/app/cache"
|
15 |
+
if not os.path.exists(cache_dir):
|
16 |
+
os.makedirs(cache_dir, exist_ok=True)
|
17 |
|
18 |
# Load model with custom cache directory
|
19 |
model = SentenceTransformer("clip-ViT-B-32")
|