Spaces:
Sleeping
Sleeping
Fedir Zadniprovskyi
commited on
Commit
•
8ad3023
1
Parent(s):
109bee8
chore: Dockerfile envs, log ws close, etc.
Browse files- Dockerfile.cpu +2 -0
- Dockerfile.cuda +2 -0
- Taskfile.yaml +2 -2
- speaches/config.py +1 -1
- speaches/main.py +5 -14
Dockerfile.cpu
CHANGED
@@ -12,3 +12,5 @@ RUN poetry install
|
|
12 |
COPY ./speaches ./speaches
|
13 |
ENTRYPOINT ["poetry", "run"]
|
14 |
CMD ["uvicorn", "speaches.main:app"]
|
|
|
|
|
|
12 |
COPY ./speaches ./speaches
|
13 |
ENTRYPOINT ["poetry", "run"]
|
14 |
CMD ["uvicorn", "speaches.main:app"]
|
15 |
+
ENV MODEL_SIZE=distil-small.en
|
16 |
+
ENV DEVICE=cpu
|
Dockerfile.cuda
CHANGED
@@ -12,3 +12,5 @@ RUN poetry install
|
|
12 |
COPY ./speaches ./speaches
|
13 |
ENTRYPOINT ["poetry", "run"]
|
14 |
CMD ["uvicorn", "speaches.main:app"]
|
|
|
|
|
|
12 |
COPY ./speaches ./speaches
|
13 |
ENTRYPOINT ["poetry", "run"]
|
14 |
CMD ["uvicorn", "speaches.main:app"]
|
15 |
+
ENV MODEL_SIZE=distil-medium.en
|
16 |
+
ENV DEVICE=cuda
|
Taskfile.yaml
CHANGED
@@ -8,8 +8,8 @@ tasks:
|
|
8 |
- "**/*.py"
|
9 |
build-and-push:
|
10 |
cmds:
|
11 |
-
- docker compose build --push
|
12 |
sources:
|
13 |
-
- Dockerfile
|
14 |
- speaches/*.py
|
15 |
sync: lsyncd -nodaemon -delay 0 -rsyncssh . gpu-box speaches
|
|
|
8 |
- "**/*.py"
|
9 |
build-and-push:
|
10 |
cmds:
|
11 |
+
- docker compose build --push
|
12 |
sources:
|
13 |
+
- Dockerfile.*
|
14 |
- speaches/*.py
|
15 |
sync: lsyncd -nodaemon -delay 0 -rsyncssh . gpu-box speaches
|
speaches/config.py
CHANGED
@@ -10,7 +10,7 @@ BYTES_PER_SECOND = SAMPLES_PER_SECOND * BYTES_PER_SAMPLE
|
|
10 |
# 1 SECOND OF AUDIO = 32000 BYTES = 16000 SAMPLES
|
11 |
|
12 |
|
13 |
-
#
|
14 |
class Model(enum.StrEnum):
|
15 |
TINY_EN = "tiny.en"
|
16 |
TINY = "tiny"
|
|
|
10 |
# 1 SECOND OF AUDIO = 32000 BYTES = 16000 SAMPLES
|
11 |
|
12 |
|
13 |
+
# https://huggingface.co/Systran
|
14 |
class Model(enum.StrEnum):
|
15 |
TINY_EN = "tiny.en"
|
16 |
TINY = "tiny"
|
speaches/main.py
CHANGED
@@ -7,14 +7,8 @@ from contextlib import asynccontextmanager
|
|
7 |
from io import BytesIO
|
8 |
from typing import Annotated
|
9 |
|
10 |
-
from fastapi import (
|
11 |
-
|
12 |
-
FastAPI,
|
13 |
-
Response,
|
14 |
-
UploadFile,
|
15 |
-
WebSocket,
|
16 |
-
WebSocketDisconnect,
|
17 |
-
)
|
18 |
from fastapi.websockets import WebSocketState
|
19 |
from faster_whisper import WhisperModel
|
20 |
from faster_whisper.vad import VadOptions, get_speech_timestamps
|
@@ -24,11 +18,8 @@ from speaches.audio import AudioStream, audio_samples_from_file
|
|
24 |
from speaches.config import SAMPLES_PER_SECOND, Language, config
|
25 |
from speaches.core import Transcription
|
26 |
from speaches.logger import logger
|
27 |
-
from speaches.server_models import (
|
28 |
-
|
29 |
-
TranscriptionResponse,
|
30 |
-
TranscriptionVerboseResponse,
|
31 |
-
)
|
32 |
from speaches.transcriber import audio_transcriber
|
33 |
|
34 |
whisper: WhisperModel = None # type: ignore
|
@@ -158,5 +149,5 @@ async def transcribe_stream(
|
|
158 |
await ws.send_text(format_transcription(transcription, response_format))
|
159 |
|
160 |
if not ws.client_state == WebSocketState.DISCONNECTED:
|
161 |
-
|
162 |
await ws.close()
|
|
|
7 |
from io import BytesIO
|
8 |
from typing import Annotated
|
9 |
|
10 |
+
from fastapi import (Depends, FastAPI, Response, UploadFile, WebSocket,
|
11 |
+
WebSocketDisconnect)
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
from fastapi.websockets import WebSocketState
|
13 |
from faster_whisper import WhisperModel
|
14 |
from faster_whisper.vad import VadOptions, get_speech_timestamps
|
|
|
18 |
from speaches.config import SAMPLES_PER_SECOND, Language, config
|
19 |
from speaches.core import Transcription
|
20 |
from speaches.logger import logger
|
21 |
+
from speaches.server_models import (ResponseFormat, TranscriptionResponse,
|
22 |
+
TranscriptionVerboseResponse)
|
|
|
|
|
|
|
23 |
from speaches.transcriber import audio_transcriber
|
24 |
|
25 |
whisper: WhisperModel = None # type: ignore
|
|
|
149 |
await ws.send_text(format_transcription(transcription, response_format))
|
150 |
|
151 |
if not ws.client_state == WebSocketState.DISCONNECTED:
|
152 |
+
logger.info("Closing the connection.")
|
153 |
await ws.close()
|