Spaces:
Sleeping
Sleeping
Arseniy Savin commited on
Commit ·
d7ee472
1
Parent(s): 740950d
Enhance Dockerfile and main.py for improved caching and health check endpoint
Browse filesUpdated the Dockerfile to include additional system dependencies and set up writable cache directories for user data. Added environment variables to manage cache paths effectively. In main.py, introduced a new root endpoint to return a simple status check, improving the application's health monitoring capabilities.
- Dockerfile +10 -1
- main.py +5 -0
Dockerfile
CHANGED
|
@@ -2,11 +2,20 @@ FROM python:3.11-slim
|
|
| 2 |
|
| 3 |
# Install system dependencies
|
| 4 |
RUN apt-get update \
|
| 5 |
-
&& apt-get install -y --no-install-recommends ffmpeg \
|
| 6 |
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
WORKDIR /app
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Python dependencies
|
| 11 |
COPY requirements.txt /app/requirements.txt
|
| 12 |
RUN pip install --no-cache-dir -r /app/requirements.txt
|
|
|
|
| 2 |
|
| 3 |
# Install system dependencies
|
| 4 |
RUN apt-get update \
|
| 5 |
+
&& apt-get install -y --no-install-recommends ffmpeg libgomp1 \
|
| 6 |
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
+
# Ensure cache directories are writable and avoid '/.cache' root path
|
| 11 |
+
ENV HOME=/app \
|
| 12 |
+
XDG_CACHE_HOME=/app/.cache \
|
| 13 |
+
HF_HOME=/app/.cache/huggingface \
|
| 14 |
+
CTRANSLATE2_CACHE_DIR=/app/.cache/ctranslate2
|
| 15 |
+
|
| 16 |
+
RUN mkdir -p "$XDG_CACHE_HOME" "$HF_HOME" "$CTRANSLATE2_CACHE_DIR" \
|
| 17 |
+
&& chmod -R 777 /app/.cache
|
| 18 |
+
|
| 19 |
# Python dependencies
|
| 20 |
COPY requirements.txt /app/requirements.txt
|
| 21 |
RUN pip install --no-cache-dir -r /app/requirements.txt
|
main.py
CHANGED
|
@@ -54,6 +54,11 @@ class _ModelHolder:
|
|
| 54 |
return cls._model
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
@app.get("/health")
|
| 58 |
def health() -> Dict[str, Any]:
|
| 59 |
return {"status": "ok"}
|
|
|
|
| 54 |
return cls._model
|
| 55 |
|
| 56 |
|
| 57 |
+
@app.get("/")
|
| 58 |
+
def root() -> Dict[str, Any]:
|
| 59 |
+
return {"status": "ok"}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
@app.get("/health")
|
| 63 |
def health() -> Dict[str, Any]:
|
| 64 |
return {"status": "ok"}
|