Spaces:
Configuration error
Configuration error
Fedir Zadniprovskyi
commited on
Commit
·
db500b1
1
Parent(s):
3431d63
chore: allow configuring the default language and response format
Browse files- speaches/config.py +6 -0
- speaches/main.py +5 -5
speaches/config.py
CHANGED
@@ -3,6 +3,8 @@ import enum
|
|
3 |
from pydantic import BaseModel, Field
|
4 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
5 |
|
|
|
|
|
6 |
SAMPLES_PER_SECOND = 16000
|
7 |
BYTES_PER_SAMPLE = 2
|
8 |
BYTES_PER_SECOND = SAMPLES_PER_SECOND * BYTES_PER_SAMPLE
|
@@ -167,6 +169,10 @@ class Config(BaseSettings):
|
|
167 |
model_config = SettingsConfigDict(env_nested_delimiter="_")
|
168 |
|
169 |
log_level: str = "info" # ENV: LOG_LEVEL
|
|
|
|
|
|
|
|
|
170 |
whisper: WhisperConfig = WhisperConfig() # ENV: WHISPER_*
|
171 |
"""
|
172 |
Max duration to for the next audio chunk before transcription is finilized and connection is closed.
|
|
|
3 |
from pydantic import BaseModel, Field
|
4 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
5 |
|
6 |
+
from speaches.server_models import ResponseFormat
|
7 |
+
|
8 |
SAMPLES_PER_SECOND = 16000
|
9 |
BYTES_PER_SAMPLE = 2
|
10 |
BYTES_PER_SECOND = SAMPLES_PER_SECOND * BYTES_PER_SAMPLE
|
|
|
169 |
model_config = SettingsConfigDict(env_nested_delimiter="_")
|
170 |
|
171 |
log_level: str = "info" # ENV: LOG_LEVEL
|
172 |
+
default_language: Language | None = None # ENV: DEFAULT_LANGUAGE
|
173 |
+
default_response_format: ResponseFormat = (
|
174 |
+
ResponseFormat.JSON
|
175 |
+
) # ENV: DEFAULT_RESPONSE_FORMAT
|
176 |
whisper: WhisperConfig = WhisperConfig() # ENV: WHISPER_*
|
177 |
"""
|
178 |
Max duration to for the next audio chunk before transcription is finilized and connection is closed.
|
speaches/main.py
CHANGED
@@ -55,7 +55,7 @@ async def translate_file(
|
|
55 |
file: Annotated[UploadFile, Form()],
|
56 |
model: Annotated[Model, Form()] = config.whisper.model,
|
57 |
prompt: Annotated[str | None, Form()] = None,
|
58 |
-
response_format: Annotated[ResponseFormat, Form()] =
|
59 |
temperature: Annotated[float, Form()] = 0.0,
|
60 |
stream: Annotated[bool, Form()] = False,
|
61 |
):
|
@@ -108,9 +108,9 @@ async def translate_file(
|
|
108 |
async def transcribe_file(
|
109 |
file: Annotated[UploadFile, Form()],
|
110 |
model: Annotated[Model, Form()] = config.whisper.model,
|
111 |
-
language: Annotated[Language | None, Form()] =
|
112 |
prompt: Annotated[str | None, Form()] = None,
|
113 |
-
response_format: Annotated[ResponseFormat, Form()] =
|
114 |
temperature: Annotated[float, Form()] = 0.0,
|
115 |
timestamp_granularities: Annotated[
|
116 |
list[Literal["segments"] | Literal["words"]],
|
@@ -223,9 +223,9 @@ def format_transcription(
|
|
223 |
async def transcribe_stream(
|
224 |
ws: WebSocket,
|
225 |
model: Annotated[Model, Query()] = config.whisper.model,
|
226 |
-
language: Annotated[Language | None, Query()] =
|
227 |
prompt: Annotated[str | None, Query()] = None,
|
228 |
-
response_format: Annotated[ResponseFormat, Query()] =
|
229 |
temperature: Annotated[float, Query()] = 0.0,
|
230 |
timestamp_granularities: Annotated[
|
231 |
list[Literal["segments"] | Literal["words"]],
|
|
|
55 |
file: Annotated[UploadFile, Form()],
|
56 |
model: Annotated[Model, Form()] = config.whisper.model,
|
57 |
prompt: Annotated[str | None, Form()] = None,
|
58 |
+
response_format: Annotated[ResponseFormat, Form()] = config.default_response_format,
|
59 |
temperature: Annotated[float, Form()] = 0.0,
|
60 |
stream: Annotated[bool, Form()] = False,
|
61 |
):
|
|
|
108 |
async def transcribe_file(
|
109 |
file: Annotated[UploadFile, Form()],
|
110 |
model: Annotated[Model, Form()] = config.whisper.model,
|
111 |
+
language: Annotated[Language | None, Form()] = config.default_language,
|
112 |
prompt: Annotated[str | None, Form()] = None,
|
113 |
+
response_format: Annotated[ResponseFormat, Form()] = config.default_response_format,
|
114 |
temperature: Annotated[float, Form()] = 0.0,
|
115 |
timestamp_granularities: Annotated[
|
116 |
list[Literal["segments"] | Literal["words"]],
|
|
|
223 |
async def transcribe_stream(
|
224 |
ws: WebSocket,
|
225 |
model: Annotated[Model, Query()] = config.whisper.model,
|
226 |
+
language: Annotated[Language | None, Query()] = config.default_language,
|
227 |
prompt: Annotated[str | None, Query()] = None,
|
228 |
+
response_format: Annotated[ResponseFormat, Query()] = config.default_response_format,
|
229 |
temperature: Annotated[float, Query()] = 0.0,
|
230 |
timestamp_granularities: Annotated[
|
231 |
list[Literal["segments"] | Literal["words"]],
|