File size: 996 Bytes
321a434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bbe8e9
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
FROM python:3.10-slim

WORKDIR /app

COPY . /app

# Install dependencies
RUN pip install --no-cache-dir -r requirements_product.txt

# Create a non-root user (match HF Spaces' default UID)
RUN useradd -m -u 1000 appuser

# Create cache and config directories in /data (persistent storage)
RUN mkdir -p /data/hf_cache /data/streamlit_config && \
    chown -R appuser:appuser /data/hf_cache /data/streamlit_config /app && \
    chmod -R 775 /data/hf_cache /data/streamlit_config /app

# Clean up any lock files in the cache
RUN rm -rf /data/hf_cache/huggingface/hub/*

# Set environment variables for Hugging Face and Streamlit
ENV HF_HOME=/data/hf_cache
ENV TRANSFORMERS_CACHE=/data/hf_cache
ENV STREAMLIT_HOME=/data/streamlit_config
ENV STREAMLIT_CONFIG_DIR=/data/streamlit_config

# Switch to non-root user
USER appuser

# Expose ports
EXPOSE 7860
EXPOSE 8000

CMD ["bash", "-c", "uvicorn server:app --host 0.0.0.0 --port 8000 & streamlit run app.py --server.port 7860 --server.address 0.0.0.0"]