FROM python:3.9-slim

# Install git, gcc, and python3-dev
RUN apt-get update && apt-get install -y \
    git \
    gcc \
    python3-dev

# Add a new user with UID 1000
RUN useradd -m -u 1000 user

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

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

# Copy the entire contents of the 'app' directory into the container
COPY . .

# Change ownership of the '/app' directory to the newly created user
RUN chown -R user:user /app

# Switch to the newly created user
USER user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Change working directory to the 'app' directory
WORKDIR /app

# Expose port 7000 for the Gradio UI
EXPOSE 7000

# Command to run the Gradio UI
CMD ["python", "main.py"]