Skip to content

Commit

Permalink
Added separate values to whisperai provider for connection and read t…
Browse files Browse the repository at this point in the history
…imeouts

Added "response" key with default value of 5 to pair with existing "timeout" key which has a default of 3600 sec.
Both values can be updated in WhisperAI settings dialog by user.
More information about these timeouts here: https://reqbin.com/code/python/3zdpeao1/python-requests-timeout-example
  • Loading branch information
JaiZed authored Jan 29, 2024
1 parent cdf7296 commit 938f6df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions bazarr/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class Validator(OriginalValidator):

# whisperai section
Validator('whisperai.endpoint', must_exist=True, default='http://127.0.0.1:9000', is_type_of=str),
Validator('whisperai.response', must_exist=True, default=5, is_type_of=int, gte=1),
Validator('whisperai.timeout', must_exist=True, default=3600, is_type_of=int, gte=1),
Validator('whisperai.loglevel', must_exist=True, default='INFO', is_type_of=str,
is_in=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']),
Expand Down
1 change: 1 addition & 0 deletions bazarr/app/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def get_providers_auth():
},
'whisperai': {
'endpoint': settings.whisperai.endpoint,
'response': settings.whisperai.response,
'timeout': settings.whisperai.timeout,
'ffmpeg_path': _FFMPEG_BINARY,
'loglevel': settings.whisperai.loglevel,
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/pages/Settings/Providers/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
defaultValue: "http://127.0.0.1:9000",
name: "Whisper ASR Docker Endpoint",
},
{
type: "text",
key: "response",
defaultValue: 5,
name: "Connection/response timeout in seconds",
},
{
type: "text",
key: "timeout",
Expand Down
12 changes: 8 additions & 4 deletions libs/subliminal_patch/providers/whisperai.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,22 @@ class WhisperAIProvider(Provider):

video_types = (Episode, Movie)

def __init__(self, endpoint=None, timeout=None, ffmpeg_path=None, loglevel=None):
def __init__(self, endpoint=None, response=None, timeout=None, ffmpeg_path=None, loglevel=None):
set_log_level(loglevel)
if not endpoint:
raise ConfigurationError('Whisper Web Service Endpoint must be provided')

if not response:
raise ConfigurationError('Whisper Web Service Connection/response timeout must be provided')

if not timeout:
raise ConfigurationError('Whisper Web Service Timeout must be provided')
raise ConfigurationError('Whisper Web Service Transcription/translation timeout must be provided')

if not ffmpeg_path:
raise ConfigurationError("ffmpeg path must be provided")

self.endpoint = endpoint
self.response = int(response)
self.timeout = int(timeout)
self.session = None
self.ffmpeg_path = ffmpeg_path
Expand All @@ -248,7 +252,7 @@ def detect_language(self, path) -> Language:
r = self.session.post(f"{self.endpoint}/detect-language",
params={'encode': 'false'},
files={'audio_file': out},
timeout=(self.timeout, self.timeout))
timeout=(self.response, self.timeout))

logger.debug(f"Whisper detected language of {path} as {r.json()['detected_language']}")

Expand Down Expand Up @@ -326,7 +330,7 @@ def download_subtitle(self, subtitle: WhisperAISubtitle):
r = self.session.post(f"{self.endpoint}/asr",
params={'task': subtitle.task, 'language': whisper_get_language_reverse(subtitle.audio_language), 'output': 'srt', 'encode': 'false'},
files={'audio_file': out},
timeout=(self.timeout, self.timeout))
timeout=(self.response, self.timeout))

endTime = time.time()
elapsedTime = timedelta(seconds=round(endTime - startTime))
Expand Down

0 comments on commit 938f6df

Please sign in to comment.