FROM python:3.11 WORKDIR /app # Copy requirements first for better caching COPY requirements.txt /app/ # Install dependencies and upgrade pip RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # Copy remaining application code COPY . /app # Create necessary directories with correct permissions RUN mkdir -p /app/back_end/data && chmod -R 777 /app/back_end/data # Set SQLite permissions and initialize database RUN python -c "import sqlite3; conn = sqlite3.connect('/app/back_end/data/veludb.db'); \ conn.execute('CREATE TABLE IF NOT EXISTS chatbot_responses (prompt TEXT, response TEXT)'); conn.close()" \ && chmod 777 /app/back_end/data/veludb.db # Install additional dependencies RUN apt-get update && apt-get install -y tmux # Ensure the Hugging Face cache is set correctly ENV HF_HOME="/app/.cache/huggingface" # Set Python path ENV PYTHONPATH="/app/" # Expose ports for FastAPI (8000) and Streamlit (7860) EXPOSE 8000 7860 # Set correct user permissions USER root RUN chown -R 1000:1000 /app/back_end/data USER 1000 # Start FastAPI and Streamlit correctly CMD ["sh", "-c", "ls -lah /app/back_end/data && \ python -c 'import sqlite3; print(sqlite3.connect(\"/app/back_end/data/veludb.db\"))' && \ tmux new-session -d 'uvicorn back_end.application.main:app --host 0.0.0.0 --port 8000' && \ sleep 5 && \ streamlit run front_end/app.py --server.port 7860 --server.address 0.0.0.0"]