File size: 1,637 Bytes
6b98981
 
 
ec40ef6
6b98981
 
 
 
ec40ef6
6b98981
 
ab21ced
ec40ef6
 
 
6b98981
 
 
ec40ef6
 
 
 
 
6b98981
 
 
ec40ef6
 
 
6b98981
 
 
 
 
 
 
 
0fa9a53
 
 
6b98981
 
 
 
ab21ced
 
 
 
 
 
 
 
 
6b98981
ec40ef6
6b98981
 
 
 
ab21ced
 
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
53
54
55
56
57
58
59
60
61
62
# Use official Python 3.11 as base image
FROM python:3.11-slim

# Install system dependencies including timezone data
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    git \
    tzdata \
    && rm -rf /var/lib/apt/lists/*

# Set timezone to Asia/Kolkata (IST) FIRST
ENV TZ=Asia/Kolkata
RUN ln -snf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime && echo Asia/Kolkata > /etc/timezone

# Set up non-root user (HF Standard)
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
	PATH=/home/user/.local/bin:$PATH \
	MPLCONFIGDIR=/tmp/.matplotlib \
	PYTHONUNBUFFERED=1 \
	PYTHONDONTWRITEBYTECODE=1 \
	TZ=Asia/Kolkata

WORKDIR $HOME/app

# Create matplotlib config directory
RUN mkdir -p /tmp/.matplotlib && chown -R user:user /tmp/.matplotlib

# Copy and install basic deps
COPY --chown=user requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir --upgrade -r requirements.txt

# Copy application files
COPY --chown=user . .

# Run training to generate placement_artifacts.pkl before starting
RUN python train_model.py

# HF Spaces only allows writing to /tmp
RUN mkdir -p /tmp/tmp && chown -R user:user /tmp/tmp
RUN ln -s /tmp/tmp tmp

# Create startup script to ensure proper logging
RUN cat > /home/user/app/entrypoint.sh << 'EOF'
#!/bin/bash
export TZ=Asia/Kolkata
export PYTHONUNBUFFERED=1
exec uvicorn main:app --host 0.0.0.0 --port 7860 --workers 4 --log-level info
EOF
RUN chmod +x /home/user/app/entrypoint.sh

# Hugging Face PORT is 7860
ENV PORT=7860

USER user
EXPOSE 7860

# Run with startup script
ENTRYPOINT ["/home/user/app/entrypoint.sh"]