Spaces:
Running
Running
Upload 3 files
Browse files- Dockerfile +10 -6
- app.py +2 -4
Dockerfile
CHANGED
|
@@ -1,21 +1,25 @@
|
|
| 1 |
-
#
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
RUN apt-get update && apt-get install -y git ffmpeg libsndfile1 && rm -rf /var/lib/apt/lists/*
|
| 6 |
|
| 7 |
# Set workdir
|
| 8 |
WORKDIR /code
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
COPY requirements.txt .
|
| 12 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
|
| 14 |
-
# Copy app
|
| 15 |
COPY app.py .
|
| 16 |
|
| 17 |
-
# Expose
|
| 18 |
EXPOSE 7860
|
| 19 |
|
| 20 |
-
#
|
| 21 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# System dependencies
|
| 5 |
RUN apt-get update && apt-get install -y git ffmpeg libsndfile1 && rm -rf /var/lib/apt/lists/*
|
| 6 |
|
| 7 |
# Set workdir
|
| 8 |
WORKDIR /code
|
| 9 |
|
| 10 |
+
# Create writable cache folder for transformers
|
| 11 |
+
RUN mkdir -p /code/.cache
|
| 12 |
+
ENV TRANSFORMERS_CACHE=/code/.cache
|
| 13 |
+
|
| 14 |
+
# Install Python dependencies
|
| 15 |
COPY requirements.txt .
|
| 16 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
+
# Copy FastAPI app
|
| 19 |
COPY app.py .
|
| 20 |
|
| 21 |
+
# Expose default HF port
|
| 22 |
EXPOSE 7860
|
| 23 |
|
| 24 |
+
# Start FastAPI
|
| 25 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
# Use a folder inside your project for caching
|
| 4 |
-
os.environ["TRANSFORMERS_CACHE"] = "/code/.cache"
|
| 5 |
|
| 6 |
from fastapi import FastAPI, Query
|
| 7 |
from fastapi.responses import FileResponse
|
|
@@ -27,7 +25,7 @@ async def tts(text: str = Query(..., description="Bambara text to synthesize")):
|
|
| 27 |
|
| 28 |
waveform = output[0]
|
| 29 |
|
| 30 |
-
# Save to
|
| 31 |
filename = f"tts_{uuid.uuid4().hex}.wav"
|
| 32 |
wavfile.write(filename, rate=sampling_rate, data=waveform.numpy())
|
| 33 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
os.environ["TRANSFORMERS_CACHE"] = "/code/.cache" # ensure writable cache
|
|
|
|
|
|
|
| 3 |
|
| 4 |
from fastapi import FastAPI, Query
|
| 5 |
from fastapi.responses import FileResponse
|
|
|
|
| 25 |
|
| 26 |
waveform = output[0]
|
| 27 |
|
| 28 |
+
# Save to temporary file
|
| 29 |
filename = f"tts_{uuid.uuid4().hex}.wav"
|
| 30 |
wavfile.write(filename, rate=sampling_rate, data=waveform.numpy())
|
| 31 |
|