Skip to content

Commit fdae104

Browse files
authored
Merge pull request #177 from thiswillbeyourgithub/add-base_url-parameter
add base url parameter
2 parents be9cf38 + aba5e09 commit fdae104

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* [x] [Hugging Face Transformers](https://huggingface.co/tasks/automatic-speech-recognition)
4747
* > Hugging Face implementation of Whisper. Any speech recognition pretrained model from the Hugging Face hub can be used as well.
4848
* [x] [API/openai/whisper](https://platform.openai.com/docs/guides/speech-to-text)
49-
* > OpenAI Whisper via their API
49+
* > OpenAI Whisper via their API. Or any other openai-like API for whisper (e.g. [speaches.ai](https://github.com/speaches-ai/speaches))
5050
5151
* Web UI
5252
* Fully offline, no third party services

src/subsai/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def merge_subs_with_video(subs: Dict[str, SSAFile],
256256
model = subs_ai.create_model('openai/whisper', {'model_type': 'tiny'})
257257
en_subs = subs_ai.transcribe(file, model)
258258
ar_subs = pysubs2.load('../../assets/video/test0-ar.srt')
259-
Tools.merge_subs_with_video2({'English': subs, "Arabic": subs2}, file)
259+
Tools.merge_subs_with_video({'English': subs, "Arabic": subs2}, file)
260260
```
261261
262262
:param subs: dict with (lang,`SSAFile` object) key,value pairs
@@ -311,5 +311,5 @@ def merge_subs_with_video(subs: Dict[str, SSAFile],
311311
subs = subs_ai.transcribe(file, model)
312312
subs.save('../../assets/video/test1.srt')
313313
subs2 = pysubs2.load('../../assets/video/test0-ar.srt')
314-
Tools.merge_subs_with_video2({'English': subs, "Arabic": subs2}, file)
314+
Tools.merge_subs_with_video({'English': subs, "Arabic": subs2}, file)
315315
# subs.save('test1.srt')

src/subsai/models/whisper_api_model.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def convert_video_to_audio_ffmpeg(video_file, output_ext="mp3"):
3737
.input(video_file)
3838
.output(output_file)
3939
.overwrite_output()
40-
.run(quiet=True)
40+
.run(quiet=False)
4141
)
4242
return output_file
4343

@@ -75,6 +75,12 @@ class WhisperAPIModel(AbstractModel):
7575
'description': "The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.",
7676
'options': None,
7777
'default': 0
78+
},
79+
'base_url': {
80+
'type': str,
81+
'description': "The base URL for the API. Useful if you're already self hosting whisper for example.",
82+
'options': None,
83+
'default': "https://api.openai.com/v1/"
7884
}
7985
}
8086

@@ -85,8 +91,11 @@ def __init__(self, model_config):
8591
self.language = _load_config('language', model_config, self.config_schema)
8692
self.prompt = _load_config('prompt', model_config, self.config_schema)
8793
self.temperature = _load_config('temperature', model_config, self.config_schema)
94+
self.base_url = _load_config('base_url', model_config, self.config_schema)
95+
if not self.base_url.endswith("/"):
96+
self.base_url += "/"
8897

89-
self.client = OpenAI(api_key=self.api_key)
98+
self.client = OpenAI(api_key=self.api_key, base_url=self.base_url)
9099

91100
def chunk_audio(self,audio_file_path) -> list:
92101
# Load the audio file

0 commit comments

Comments
 (0)