File size: 1,449 Bytes
dbd9bf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Optimized Dockerfile for Hugging Face Spaces
FROM python:3.10-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Create cache directories with proper permissions
RUN mkdir -p /tmp/transformers_cache /tmp/huggingface /tmp/torch && \
    chmod -R 777 /tmp/transformers_cache /tmp/huggingface /tmp/torch

# Copy requirements and install Python dependencies
COPY requirements.txt .

# Install dependencies in stages for better caching
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir \
    fastapi==0.104.0 \
    uvicorn[standard]==0.24.0 \
    pydantic==2.5.0 \
    python-multipart==0.0.6 \
    python-dotenv==1.0.0 \
    requests==2.31.0 \
    googletrans==4.0.0rc1 \
    langdetect==1.0.9 && \
    pip install --no-cache-dir \
    numpy==1.24.0 \
    pandas==2.0.0 \
    scikit-learn==1.3.0 && \
    pip install --no-cache-dir \
    torch==2.0.0 \
    transformers==4.35.0 \
    sentence-transformers==2.2.0

# Copy application code
COPY . .

# Expose port (Hugging Face Spaces uses 7860 by default)
EXPOSE 7860

# Set environment variables for cache directories
ENV PORT=7860
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/huggingface
ENV TORCH_HOME=/tmp/torch

# Start the application
CMD ["python", "app.py"]