Commit ·
8a14cfe
1
Parent(s): 9ff1ff0
deploy
Browse files- Dockerfile +17 -1
- services/embedding.py +8 -1
Dockerfile
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
|
|
|
|
|
|
| 2 |
WORKDIR /app
|
|
|
|
|
|
|
| 3 |
COPY requirements.txt .
|
|
|
|
|
|
|
| 4 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
EXPOSE 7860
|
|
|
|
|
|
|
| 7 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 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"]
|
services/embedding.py
CHANGED
|
@@ -3,8 +3,15 @@ from PIL import Image
|
|
| 3 |
from fastapi import UploadFile
|
| 4 |
from typing import List, Optional
|
| 5 |
import torch
|
|
|
|
| 6 |
|
| 7 |
-
model = SentenceTransformer("clip-ViT-B-32")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def get_text_embedding(text: str) -> Optional[List[float]]:
|
| 10 |
try:
|
|
|
|
| 3 |
from fastapi import UploadFile
|
| 4 |
from typing import List, Optional
|
| 5 |
import torch
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
# model = SentenceTransformer("clip-ViT-B-32")
|
| 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", cache_dir="/app/cache")
|
| 15 |
|
| 16 |
def get_text_embedding(text: str) -> Optional[List[float]]:
|
| 17 |
try:
|