File size: 1,456 Bytes
21fb9ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use Python 3.10 slim image for smaller size
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Install uv
RUN pip install uv

# Copy dependency files first (for better caching)
COPY pyproject.toml ./
COPY uv.lock ./
COPY README.md ./

# Install dependencies using uv (creates .venv)
RUN uv sync --frozen

# Use /tmp for all caches and Streamlit config to avoid permission issues in read-only paths
ENV HOME=/tmp \
	XDG_CACHE_HOME=/tmp/.cache \
	UV_CACHE_DIR=/tmp/.cache/uv \
	PIP_CACHE_DIR=/tmp/.cache/pip \
	HF_HOME=/tmp/.cache/huggingface \
	TRANSFORMERS_CACHE=/tmp/.cache/huggingface/transformers \
	TORCH_HOME=/tmp/.cache/torch \
	STREAMLIT_CONFIG_DIR=/tmp/.streamlit \
	STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
RUN mkdir -p \
	  /tmp/.cache/uv \
	  /tmp/.cache/pip \
	  /tmp/.cache/huggingface/transformers \
	  /tmp/.cache/torch \
	  /tmp/.streamlit \
	&& chmod -R 777 /tmp/.cache /tmp/.streamlit

# Copy application code
COPY src/ ./src/
COPY app.py ./
COPY config.toml ./

# Expose Streamlit port (Hugging Face Spaces uses 7860)
EXPOSE 7860

# Set environment variables for Streamlit
ENV STREAMLIT_SERVER_PORT=7860
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
ENV STREAMLIT_SERVER_HEADLESS=true
ENV STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false

# Run the application using the created virtual environment
ENV PATH="/app/.venv/bin:${PATH}"
CMD ["python", "-m", "streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]