Spaces:
Sleeping
Sleeping
CrazyMonkey0
commited on
Commit
·
65952f6
1
Parent(s):
df63d34
test(tts): checking whether the tts model is working correctly
Browse files- Dockerfile +7 -12
- app/routes/nlp.py +18 -20
Dockerfile
CHANGED
|
@@ -1,26 +1,21 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM
|
| 3 |
|
| 4 |
-
#
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
#
|
| 8 |
COPY ./requirements.txt /app/requirements.txt
|
| 9 |
|
| 10 |
-
#
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
-
#
|
| 14 |
COPY . /app
|
| 15 |
|
| 16 |
-
# Expose port
|
| 17 |
EXPOSE 7860
|
| 18 |
|
| 19 |
-
# set environment variables
|
| 20 |
-
ENV CUDA_VISIBLE_DEVICES=""
|
| 21 |
-
ENV TF_CPP_MIN_LOG_LEVEL=2
|
| 22 |
-
ENV TF_ENABLE_ONEDNN_OPTS=0
|
| 23 |
-
|
| 24 |
# Run FastAPI with Gunicorn - increased timeout for model loading
|
| 25 |
CMD ["gunicorn", "app.main:app", \
|
| 26 |
"-k", "uvicorn.workers.UvicornWorker", \
|
|
|
|
| 1 |
+
# Instead of FROM python:3.12, use a slim base image
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
|
| 4 |
+
# Set the working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy requirements.txt (llama-cpp-python is already included in the base image)
|
| 8 |
COPY ./requirements.txt /app/requirements.txt
|
| 9 |
|
| 10 |
+
# Install only project-specific dependencies
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
+
# Copy the entire application source code
|
| 14 |
COPY . /app
|
| 15 |
|
| 16 |
+
# Expose port for Hugging Face Spaces
|
| 17 |
EXPOSE 7860
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Run FastAPI with Gunicorn - increased timeout for model loading
|
| 20 |
CMD ["gunicorn", "app.main:app", \
|
| 21 |
"-k", "uvicorn.workers.UvicornWorker", \
|
app/routes/nlp.py
CHANGED
|
@@ -66,23 +66,21 @@ async def chat(request: Request, chat_request: ChatRequest):
|
|
| 66 |
skip_special_tokens=True
|
| 67 |
).strip()
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
# media_type=f"multipart/form-data; boundary={boundary}"
|
| 88 |
-
# )
|
|
|
|
| 66 |
skip_special_tokens=True
|
| 67 |
).strip()
|
| 68 |
|
| 69 |
+
# Generate audio using TTS
|
| 70 |
+
audio_bytes = save_audio(request, response_text)
|
| 71 |
+
|
| 72 |
+
# Create a multipart response
|
| 73 |
+
boundary = uuid.uuid4().hex
|
| 74 |
+
body = (
|
| 75 |
+
f"--{boundary}\r\n"
|
| 76 |
+
f"Content-Disposition: form-data; name=\"text\"\r\n\r\n"
|
| 77 |
+
f"{response_text}\r\n"
|
| 78 |
+
f"--{boundary}\r\n"
|
| 79 |
+
f"Content-Disposition: form-data; name=\"audio\"; filename=\"speech.wav\"\r\n"
|
| 80 |
+
f"Content-Type: audio/wav\r\n\r\n"
|
| 81 |
+
).encode() + audio_bytes + f"\r\n--{boundary}--\r\n".encode()
|
| 82 |
+
|
| 83 |
+
return Response(
|
| 84 |
+
content=body,
|
| 85 |
+
media_type=f"multipart/form-data; boundary={boundary}"
|
| 86 |
+
)
|
|
|
|
|
|