File size: 1,083 Bytes
c6c8587
 
 
 
 
 
 
 
 
 
a3e1f56
 
 
 
 
 
 
 
 
c6c8587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Backend-only Dockerfile for Hugging Face Spaces
FROM python:3.11-slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Set environment variables for Hugging Face cache
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/hf_home
ENV HUGGINGFACE_HUB_CACHE=/tmp/huggingface_hub

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

# Copy and install Python requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy backend code
COPY backend/ ./backend/
COPY app.py .

# Create a simple health check endpoint
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Expose the Hugging Face Spaces default port
EXPOSE 7860

# Run the FastAPI app with Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]