Introduce dataclasses for configuring model settings
This commit is contained in:
@@ -32,12 +32,13 @@ from gajim.gtk.sidebar_switcher import SideBarSwitcher
|
||||
from gajim.plugins.helpers import get_builder
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from ..model_settings import *
|
||||
from ..models import openai_whisper
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..stt_voice_messages import STTVoiceMessagesPlugin
|
||||
|
||||
log = logging.getLogger('gajim.p.stt_voice_messages_config_dialog')
|
||||
log = logging.getLogger('gajim.p.sttvm_config_dialog')
|
||||
|
||||
|
||||
SUPPORTED_MODELS: dict[str, dict[str, typing.Union[list[str], Any, str]]] = {
|
||||
@@ -67,6 +68,7 @@ SUPPORTED_MODELS: dict[str, dict[str, typing.Union[list[str], Any, str]]] = {
|
||||
class Configuration:
|
||||
def __init__(self, plugin: STTVoiceMessagesPlugin):
|
||||
self._plugin = plugin
|
||||
self._openaiwhisper_settings = OpenAIWhisperSettings()
|
||||
self._available_models: dict[
|
||||
str, dict[str, typing.Union[list[str], Any, str]]] = {}
|
||||
self.check_available_moduls()
|
||||
@@ -84,14 +86,20 @@ class Configuration:
|
||||
value.strip()
|
||||
log.debug('plugin config before:\n %s', self.plugin.config.data)
|
||||
self.plugin.config[data] = value
|
||||
self._plugin.config['model_instance'].on_setting(data, value)
|
||||
log.debug('plugin config after:\n %s', self.plugin.config.data)
|
||||
|
||||
def on_set_model(self, value: Any, data: Any) -> None:
|
||||
if isinstance(value, str):
|
||||
value.strip()
|
||||
log.debug('plugin config before:\n %s', self.plugin.config.data)
|
||||
|
||||
self._available_models[value]['model_instance'] = self._available_models[value]['class']()
|
||||
|
||||
self.plugin.config['model_class'] = self._available_models[value][
|
||||
'class']
|
||||
self.plugin.config['model_instance'] = self._available_models[value]['model_instance']
|
||||
|
||||
self.on_setting(value, data)
|
||||
log.debug('plugin config after:\n %s', self.plugin.config.data)
|
||||
|
||||
|
||||
@@ -49,26 +49,29 @@ class STTBox(Gtk.Box):
|
||||
self.add(self._transcribe_button)
|
||||
self.add(self._transcription_label)
|
||||
|
||||
self._result = helper.Results('')
|
||||
|
||||
self._transcribe_button.connect('clicked', self._on_transcribe_clicked)
|
||||
|
||||
self.show_all()
|
||||
|
||||
def _on_transcribe_clicked(self, _button: Gtk.Button) -> None:
|
||||
log.debug('config.data = %s', self._config.data)
|
||||
model_class = self._config.data['model_class']
|
||||
if model_class is None:
|
||||
model = self._config.data['model_instance']
|
||||
if model is None:
|
||||
return
|
||||
|
||||
self._model = model_class()
|
||||
self._model = model
|
||||
|
||||
transcription_task = helper.BackgroundTask(
|
||||
self._model.transcribe(self._audio_file),
|
||||
self._model.transcribe(self._result, self._audio_file),
|
||||
self._show_result
|
||||
)
|
||||
transcription_task.start()
|
||||
|
||||
def _show_result(self):
|
||||
self._text = self._model.result
|
||||
assert self._model is not None
|
||||
self._text = self._result.text
|
||||
if self._text.strip() != '':
|
||||
self._transcription_label.set_text(self._text.strip())
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user