Introduce dataclasses for configuring model settings

This commit is contained in:
mesonium
2024-06-18 15:15:52 +02:00
committed by hueso
parent f5db7f9809
commit 36c96b4a16
6 changed files with 68 additions and 20 deletions

View File

@@ -13,12 +13,16 @@
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import logging
import typing
from dataclasses import dataclass
from pathlib import Path
from ..helper import Results
from ..model_settings import OpenAIWhisperSettings
from .model import Model
from gajim.gtk.const import Setting
log = logging.getLogger('gajim.p.sttvm_whisper')
try:
import whisper
@@ -27,27 +31,26 @@ except ModuleNotFoundError:
if typing.TYPE_CHECKING:
import whisper
@dataclass
class Configuration:
model_size: str
class WhisperModel(Model):
def __init__(self):
# TODO
self._model_sizes = ['tiny', 'small', 'base', 'medium', 'large']
self._multilanguage = True
self._result: str = ''
self._config = {
'model_size': 'tiny'
}
self._config = OpenAIWhisperSettings()
@property
def result(self) -> str:
return self._result
def transcribe(self, audio_file: Path) -> str:
model = whisper.load_model(self._config['model_size'])
result = model.transcribe(audio_file)
self._result = result['text']
def transcribe(self, result: Results, audio_file: Path) -> str:
model = whisper.load_model(self._config['whisperai_model_size'])
log.debug('model size is used = %s', self._config['whisperai_model_size'])
result.text = model.transcribe(audio_file)['text']
def on_setting(self, setting: Setting):
pass
def on_setting(self, key, value):
log.debug('key = %s, value = %s', key, value)
self._config[key] = value