|
FROM python:3.12-slim |
|
|
|
# Set working directory |
|
WORKDIR /app |
|
|
|
# Install system dependencies |
|
RUN apt-get update && apt-get install -y \ |
|
curl \ |
|
&& rm -rf /var/lib/apt/lists/* |
|
|
|
# Copy requirements and install Python dependencies |
|
COPY pyproject.toml uv.lock ./ |
|
RUN pip install uv && uv sync --frozen |
|
|
|
# Copy application code |
|
COPY . . |
|
|
|
# Verify dependencies are installed |
|
RUN .venv/bin/python -c "import pandas, datasets, evaluate, fastapi, uvicorn, google.cloud.storage, google.cloud.translate, dotenv, elevenlabs, huggingface_hub, joblib, language_data, openai, requests, scipy, aiolimiter, sentencepiece, langcodes, rich, tqdm; print('β
All dependencies verified')" |
|
|
|
# Set environment variables with conservative limits |
|
ENV N_SENTENCES=20 |
|
ENV MAX_LANGUAGES=150 |
|
ENV COST_LIMIT_USD=20 |
|
|
|
# Create a startup script with cost monitoring and HTTP server |
|
RUN echo '#!/bin/bash\n\ |
|
\n\ |
|
# Force immediate log flushing for Cloud Run visibility\n\ |
|
export PYTHONUNBUFFERED=1\n\ |
|
export PYTHONIOENCODING=utf-8\n\ |
|
\n\ |
|
echo "π Starting AI Language Evaluation..."\n\ |
|
echo "π Configuration: $N_SENTENCES sentences, $MAX_LANGUAGES languages"\n\ |
|
echo "π° Cost limit: $COST_LIMIT_USD USD"\n\ |
|
echo "π‘οΈ Cost protection enabled"\n\ |
|
echo "π§ Logging: Unbuffered Python output enabled"\n\ |
|
\n\ |
|
|
|
python -m http.server 8080 &\n\ |
|
HTTP_SERVER_PID=$!\n\ |
|
\n\ |
|
|
|
(\n\ |
|
start_time=$(date +%s)\n\ |
|
while true; do\n\ |
|
current_time=$(date +%s)\n\ |
|
elapsed_hours=$(( (current_time - start_time) / 3600 ))\n\ |
|
if [ $elapsed_hours -ge 24 ]; then\n\ |
|
echo "β οΈ MAX RUNTIME REACHED! Stopping evaluation..."\n\ |
|
pkill -f "python evals/main_gcs.py"\n\ |
|
break\n\ |
|
fi\n\ |
|
sleep 300 |
|
done\n\ |
|
) &\n\ |
|
\n\ |
|
|
|
cd /app && .venv/bin/python -u evals/main_gcs.py\n\ |
|
\n\ |
|
|
|
kill $HTTP_SERVER_PID\n\ |
|
\n\ |
|
echo "β
Evaluation completed!"\n\ |
|
' > /app/start.sh && chmod +x /app/start.sh |
|
|
|
# Expose port (for Cloud Run requirements) |
|
EXPOSE 8080 |
|
|
|
# Run the evaluation with resource limits |
|
CMD ["/app/start.sh"] |