pravaah / Dockerfile
Prathamesh Sutar
Initial deployment of Pravaah Ocean Hazard Detection System
49e67a8
raw
history blame
1.59 kB
# Dockerfile for Hugging Face Spaces with FastAPI + Gradio
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set the working directory inside the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file and install dependencies first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy all your application code into the container
COPY . .
# IMPORTANT: Download and cache the models during the build process.
# This makes the application start much faster when the Space wakes up.
RUN python -c "from classifier import classify_with_model; classify_with_model('test')"
RUN python -c "from ner import get_ner_pipeline; get_ner_pipeline()"
RUN python -c "from sentiment import get_emotion_classifier; get_emotion_classifier()"
RUN python -c "from translate import get_translator; get_translator()"
# Create startup script
RUN echo '#!/bin/bash\n\
echo "πŸš€ Starting FastAPI server on port 8000..."\n\
python -m uvicorn api:app --host 0.0.0.0 --port 8000 &\n\
echo "🌊 Starting Gradio web interface on port 7860..."\n\
python app.py' > start_services.sh
RUN chmod +x start_services.sh
# Expose ports for both services
EXPOSE 7860 # Gradio web interface
EXPOSE 8000 # FastAPI
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Start both services
CMD ["./start_services.sh"]