Fedir Zadniprovskyi commited on
Commit
d16cb74
·
1 Parent(s): db500b1

chore: don't raise when specified model isn't the default one

Browse files
Files changed (1) hide show
  1. speaches/main.py +23 -16
speaches/main.py CHANGED
@@ -37,8 +37,9 @@ async def lifespan(_: FastAPI):
37
  device=config.whisper.inference_device,
38
  compute_type=config.whisper.compute_type,
39
  )
40
- end = time.perf_counter()
41
- logger.debug(f"Loaded {config.whisper.model} loaded in {end - start:.2f} seconds")
 
42
  yield
43
 
44
 
@@ -59,9 +60,10 @@ async def translate_file(
59
  temperature: Annotated[float, Form()] = 0.0,
60
  stream: Annotated[bool, Form()] = False,
61
  ):
62
- assert (
63
- model == config.whisper.model
64
- ), "Specifying a model that is different from the default is not supported yet."
 
65
  start = time.perf_counter()
66
  segments, transcription_info = whisper.transcribe(
67
  file.file,
@@ -86,9 +88,8 @@ async def translate_file(
86
 
87
  if not stream:
88
  segments = list(segments)
89
- end = time.perf_counter()
90
  logger.info(
91
- f"Translated {transcription_info.duration}({transcription_info.duration_after_vad}) seconds of audio in {end - start:.2f} seconds"
92
  )
93
  if response_format == ResponseFormat.TEXT:
94
  return utils.segments_text(segments)
@@ -118,9 +119,10 @@ async def transcribe_file(
118
  ] = ["segments"],
119
  stream: Annotated[bool, Form()] = False,
120
  ):
121
- assert (
122
- model == config.whisper.model
123
- ), "Specifying a model that is different from the default is not supported yet."
 
124
  start = time.perf_counter()
125
  segments, transcription_info = whisper.transcribe(
126
  file.file,
@@ -134,6 +136,9 @@ async def transcribe_file(
134
 
135
  def segment_responses():
136
  for segment in segments:
 
 
 
137
  if response_format == ResponseFormat.TEXT:
138
  yield segment.text
139
  elif response_format == ResponseFormat.JSON:
@@ -147,9 +152,8 @@ async def transcribe_file(
147
 
148
  if not stream:
149
  segments = list(segments)
150
- end = time.perf_counter()
151
  logger.info(
152
- f"Transcribed {transcription_info.duration}({transcription_info.duration_after_vad}) seconds of audio in {end - start:.2f} seconds"
153
  )
154
  if response_format == ResponseFormat.TEXT:
155
  return utils.segments_text(segments)
@@ -225,7 +229,9 @@ async def transcribe_stream(
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"]],
@@ -235,9 +241,10 @@ async def transcribe_stream(
235
  ),
236
  ] = ["segments", "words"],
237
  ) -> None:
238
- assert (
239
- model == config.whisper.model
240
- ), "Specifying a model that is different from the default is not supported yet."
 
241
  await ws.accept()
242
  transcribe_opts = {
243
  "language": language,
 
37
  device=config.whisper.inference_device,
38
  compute_type=config.whisper.compute_type,
39
  )
40
+ logger.debug(
41
+ f"Loaded {config.whisper.model} loaded in {time.perf_counter() - start:.2f} seconds"
42
+ )
43
  yield
44
 
45
 
 
60
  temperature: Annotated[float, Form()] = 0.0,
61
  stream: Annotated[bool, Form()] = False,
62
  ):
63
+ if model != config.whisper.model:
64
+ logger.warning(
65
+ f"Specifying a model that is different from the default is not supported yet. Using {config.whisper.model}."
66
+ )
67
  start = time.perf_counter()
68
  segments, transcription_info = whisper.transcribe(
69
  file.file,
 
88
 
89
  if not stream:
90
  segments = list(segments)
 
91
  logger.info(
92
+ f"Translated {transcription_info.duration}({transcription_info.duration_after_vad}) seconds of audio in {time.perf_counter() - start:.2f} seconds"
93
  )
94
  if response_format == ResponseFormat.TEXT:
95
  return utils.segments_text(segments)
 
119
  ] = ["segments"],
120
  stream: Annotated[bool, Form()] = False,
121
  ):
122
+ if model != config.whisper.model:
123
+ logger.warning(
124
+ f"Specifying a model that is different from the default is not supported yet. Using {config.whisper.model}."
125
+ )
126
  start = time.perf_counter()
127
  segments, transcription_info = whisper.transcribe(
128
  file.file,
 
136
 
137
  def segment_responses():
138
  for segment in segments:
139
+ logger.info(
140
+ f"Transcribed {segment.end - segment.start} seconds of audio in {time.perf_counter() - start:.2f} seconds"
141
+ )
142
  if response_format == ResponseFormat.TEXT:
143
  yield segment.text
144
  elif response_format == ResponseFormat.JSON:
 
152
 
153
  if not stream:
154
  segments = list(segments)
 
155
  logger.info(
156
+ f"Transcribed {transcription_info.duration}({transcription_info.duration_after_vad}) seconds of audio in {time.perf_counter() - start:.2f} seconds"
157
  )
158
  if response_format == ResponseFormat.TEXT:
159
  return utils.segments_text(segments)
 
229
  model: Annotated[Model, Query()] = config.whisper.model,
230
  language: Annotated[Language | None, Query()] = config.default_language,
231
  prompt: Annotated[str | None, Query()] = None,
232
+ response_format: Annotated[
233
+ ResponseFormat, Query()
234
+ ] = config.default_response_format,
235
  temperature: Annotated[float, Query()] = 0.0,
236
  timestamp_granularities: Annotated[
237
  list[Literal["segments"] | Literal["words"]],
 
241
  ),
242
  ] = ["segments", "words"],
243
  ) -> None:
244
+ if model != config.whisper.model:
245
+ logger.warning(
246
+ f"Specifying a model that is different from the default is not supported yet. Using {config.whisper.model}."
247
+ )
248
  await ws.accept()
249
  transcribe_opts = {
250
  "language": language,