Spaces:
Paused
Paused
M Farrel Danendra Rachim
commited on
Commit
·
c793691
1
Parent(s):
bdd0296
ddd
Browse files- Dockerfile +21 -10
- main.py +0 -5
Dockerfile
CHANGED
|
@@ -1,14 +1,25 @@
|
|
| 1 |
-
# Use
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Set
|
| 8 |
-
WORKDIR /
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Start the FastAPI app on port 7860, the default port expected by Spaces
|
| 14 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use a lightweight and stable Python base image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Set environment variables to prevent cache permission issues
|
| 5 |
+
ENV HF_HOME=/tmp/huggingface
|
| 6 |
+
ENV TRANSFORMERS_CACHE=/tmp/huggingface/transformers
|
| 7 |
+
ENV PIP_NO_CACHE_DIR=1
|
| 8 |
+
ENV PYTHONUNBUFFERED=1
|
| 9 |
|
| 10 |
+
# Set working directory
|
| 11 |
+
WORKDIR /app
|
| 12 |
|
| 13 |
+
# Copy files into the container
|
| 14 |
+
COPY . /app
|
| 15 |
+
|
| 16 |
+
# Install dependencies
|
| 17 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 18 |
+
pip install --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Expose the default port used by Hugging Face Spaces
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Run the FastAPI app
|
| 24 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 25 |
|
|
|
|
|
|
main.py
CHANGED
|
@@ -6,11 +6,6 @@ from happytransformer import HappyTextToText, TTSettings
|
|
| 6 |
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
# Redirect cache to a local writable path
|
| 10 |
-
os.environ["HF_HOME"] = "/tmp/huggingface"
|
| 11 |
-
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface/transformers"
|
| 12 |
-
os.makedirs("/tmp/huggingface", exist_ok=True)
|
| 13 |
-
|
| 14 |
app = FastAPI()
|
| 15 |
|
| 16 |
# Load models at startup
|
|
|
|
| 6 |
|
| 7 |
import os
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
# Load models at startup
|