Spaces:
Build error
Build error
permission fix 00
Browse files- Dockerfile +7 -6
- app/config.py +10 -3
Dockerfile
CHANGED
|
@@ -3,15 +3,16 @@ FROM python:3.10-slim
|
|
| 3 |
# 1. Create a non-root user
|
| 4 |
RUN useradd -m -u 1000 user
|
| 5 |
|
| 6 |
-
# 2. Set
|
| 7 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
-
# 3. Install ffmpeg and create folders
|
| 11 |
RUN apt-get update && apt-get install -y ffmpeg && \
|
| 12 |
-
mkdir -p static audio_sample output cache/hf cache/whisper
|
|
|
|
| 13 |
|
| 14 |
-
# 4. Switch to non-root user
|
| 15 |
USER user
|
| 16 |
|
| 17 |
# 5. Install Python dependencies
|
|
@@ -19,9 +20,9 @@ COPY --chown=user requirements.txt .
|
|
| 19 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 20 |
pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
-
# 6. Copy source code
|
| 23 |
COPY --chown=user . .
|
| 24 |
|
| 25 |
-
# 7. Expose port and
|
| 26 |
EXPOSE 7860
|
| 27 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 3 |
# 1. Create a non-root user
|
| 4 |
RUN useradd -m -u 1000 user
|
| 5 |
|
| 6 |
+
# 2. Set environment and working directory (as root)
|
| 7 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
+
# 3. Install ffmpeg and pre-create folders with correct ownership
|
| 11 |
RUN apt-get update && apt-get install -y ffmpeg && \
|
| 12 |
+
mkdir -p static audio_sample output cache/hf/transformers cache/whisper && \
|
| 13 |
+
chown -R 1000:1000 static audio_sample output cache
|
| 14 |
|
| 15 |
+
# 4. Switch to non-root user for security
|
| 16 |
USER user
|
| 17 |
|
| 18 |
# 5. Install Python dependencies
|
|
|
|
| 20 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 21 |
pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
+
# 6. Copy app source code
|
| 24 |
COPY --chown=user . .
|
| 25 |
|
| 26 |
+
# 7. Expose Hugging Face's required port and start the server
|
| 27 |
EXPOSE 7860
|
| 28 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/config.py
CHANGED
|
@@ -11,11 +11,18 @@ os.environ["TRANSFORMERS_CACHE"] = os.getenv("TRANSFORMERS_CACHE", "./cache/hf/t
|
|
| 11 |
os.environ["WHISPER_CACHE"] = os.getenv("WHISPER_CACHE", "./cache/whisper")
|
| 12 |
|
| 13 |
# Optional: create cache directories at runtime
|
| 14 |
-
|
| 15 |
-
os.
|
| 16 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Hugging Face and LLM-related keys (should be set in .env or Hugging Face Secrets)
|
| 19 |
os.environ["HUGGINGFACE_HUB_TOKEN"] = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 20 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
| 21 |
os.environ["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
os.environ["WHISPER_CACHE"] = os.getenv("WHISPER_CACHE", "./cache/whisper")
|
| 12 |
|
| 13 |
# Optional: create cache directories at runtime
|
| 14 |
+
for env_var in ["HF_HOME", "TRANSFORMERS_CACHE", "WHISPER_CACHE"]:
|
| 15 |
+
path = os.environ.get(env_var)
|
| 16 |
+
if path and not os.path.exists(path):
|
| 17 |
+
try:
|
| 18 |
+
os.makedirs(path, exist_ok=True)
|
| 19 |
+
except PermissionError:
|
| 20 |
+
print(f"⚠️ Warning: Cannot create {path}. Ensure it is writable by the app.")
|
| 21 |
|
| 22 |
# Hugging Face and LLM-related keys (should be set in .env or Hugging Face Secrets)
|
| 23 |
os.environ["HUGGINGFACE_HUB_TOKEN"] = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 24 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
| 25 |
os.environ["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|