Some more work on multi models
This commit is contained in:
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from gi.repository import Gtk
|
||||
import whisper
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.gtk.builder import get_builder
|
||||
@@ -29,17 +30,19 @@ from gajim.gtk.sidebar_switcher import SideBarSwitcher
|
||||
from gajim.plugins.helpers import get_builder
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from .. import stt_voice_messages
|
||||
from ..models import openai_whisper
|
||||
from ..configs import *
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import stt_voice_messages
|
||||
|
||||
log = logging.getLogger('gajim.p.stt_voice_messages_config')
|
||||
|
||||
|
||||
################################################################################
|
||||
# Helper
|
||||
################################################################################
|
||||
|
||||
def check_module(module: str) -> bool:
|
||||
try:
|
||||
__import__(module)
|
||||
@@ -68,7 +71,7 @@ class STTVoiceMessagesConfigDialog(Gtk.ApplicationWindow):
|
||||
self.set_name('PreferencesWindow')
|
||||
self.set_default_size(900, 650)
|
||||
self.set_resizable(True)
|
||||
self.set_title(_('Preferences'))
|
||||
self.set_title(_('STT Voice Messages - Preferences'))
|
||||
|
||||
ui_path = Path(__file__).parent
|
||||
self._ui = get_builder(str(ui_path.resolve() / 'config_dialog.ui'))
|
||||
@@ -83,7 +86,7 @@ class STTVoiceMessagesConfigDialog(Gtk.ApplicationWindow):
|
||||
('stt_behaviour', STTBehaviour),
|
||||
('models', Models),
|
||||
('file_preview', FilePreview),
|
||||
('whisper_general', openai_whisper.OpenAIWhisperGeneral),
|
||||
('whisper_general', OpenAIWhisperGeneral),
|
||||
]
|
||||
|
||||
self._add_prefs(prefs)
|
||||
@@ -92,21 +95,18 @@ class STTVoiceMessagesConfigDialog(Gtk.ApplicationWindow):
|
||||
def _add_prefs(self, prefs: list[tuple[str, type[PreferenceBox]]]):
|
||||
for ui_name, klass in prefs:
|
||||
pref_box = getattr(self._ui, ui_name)
|
||||
print('pref_box = ', pref_box)
|
||||
if pref_box is None:
|
||||
continue
|
||||
pref = klass(self) # pyright: ignore
|
||||
print("pref = ", pref)
|
||||
pref_box.add(pref)
|
||||
self._prefs[ui_name] = pref
|
||||
|
||||
def _on_setting(self, value: Any, data: Any) -> None:
|
||||
if isinstance(value, str):
|
||||
value.strip()
|
||||
self.plugin.config[data] = value
|
||||
self.plugin.update()
|
||||
|
||||
|
||||
################################################################################
|
||||
# Preference boxes
|
||||
################################################################################
|
||||
|
||||
class PreferenceBox(SettingsBox):
|
||||
def __init__(self, settings: list[Setting]) -> None:
|
||||
SettingsBox.__init__(self, None)
|
||||
@@ -120,9 +120,12 @@ class PreferenceBox(SettingsBox):
|
||||
self.update_states()
|
||||
|
||||
|
||||
################################################################################
|
||||
# General Preferences
|
||||
################################################################################
|
||||
|
||||
class STTBehaviour(PreferenceBox):
|
||||
def __init__(self, *args: Any) -> None:
|
||||
|
||||
main_window_on_startup_items = {
|
||||
'always': _('Always'),
|
||||
'never': _('Never'),
|
||||
@@ -143,7 +146,6 @@ class STTBehaviour(PreferenceBox):
|
||||
|
||||
class Models(PreferenceBox):
|
||||
def __init__(self, *args: Any) -> None:
|
||||
|
||||
main_window_on_startup_items = {
|
||||
'always': _('Always'),
|
||||
'never': _('Never'),
|
||||
@@ -164,7 +166,6 @@ class Models(PreferenceBox):
|
||||
|
||||
class FilePreview(PreferenceBox):
|
||||
def __init__(self, *args: Any) -> None:
|
||||
|
||||
main_window_on_startup_items = {
|
||||
'always': _('Always'),
|
||||
'never': _('Never'),
|
||||
@@ -183,3 +184,27 @@ class FilePreview(PreferenceBox):
|
||||
PreferenceBox.__init__(self, settings)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Whisper Settings UI
|
||||
################################################################################
|
||||
|
||||
class OpenAIWhisperGeneral(PreferenceBox):
|
||||
def __init__(self, *args: Any) -> None:
|
||||
self.config = PluginConfig().openaiwhisper
|
||||
|
||||
settings = [
|
||||
Setting(SettingKind.POPOVER,
|
||||
_('Language Model Size'),
|
||||
SettingType.VALUE,
|
||||
value=str(self.config['model_size']),
|
||||
data='model_size',
|
||||
callback=self._on_setting,
|
||||
props={'entries': whisper.available_models()}),
|
||||
]
|
||||
|
||||
PreferenceBox.__init__(self, settings)
|
||||
|
||||
def _on_setting(self, value: Any, data: Any) -> None:
|
||||
print("before: ", self.config)
|
||||
self.config[data] = value
|
||||
print("after: ", self.config)
|
||||
|
||||
@@ -12,21 +12,18 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
from pathlib import Path
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.plugins.gajimplugin import GajimPluginConfig
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from .. import helper
|
||||
|
||||
|
||||
class STTBox(Gtk.Box):
|
||||
def __init__(self,
|
||||
preview_audio_widget: Gtk.Box,
|
||||
config: GajimPluginConfig,
|
||||
audio_file: Path,
|
||||
audio_file: str,
|
||||
) -> None:
|
||||
|
||||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=12)
|
||||
@@ -39,7 +36,8 @@ class STTBox(Gtk.Box):
|
||||
|
||||
self._transcribe_button = Gtk.Button(label=_('Transcribe'))
|
||||
|
||||
self._transcription_label = Gtk.Label(label=_('Nothing transcribed yet'))
|
||||
self._transcription_label = Gtk.Label(
|
||||
label=_('Nothing transcribed yet'))
|
||||
self._transcription_label.set_max_width_chars(40)
|
||||
self._transcription_label.set_line_wrap(True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user