Skip to content

Commit

Permalink
Refactor module structure (chidiwilliams#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Nov 28, 2022
1 parent 219f20d commit f358809
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
omit =
whisper_cpp.py
buzz/whisper_cpp.py
*_test.py

[html]
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ endif

clean:
rm -f $(LIBWHISPER)
rm -f whisper_cpp.py
rm -f buzz/whisper_cpp.py
rm -rf dist/* || true

test: whisper_cpp.py
test: buzz/whisper_cpp.py
pytest --cov --cov-report=html

dist/Buzz dist/Buzz.app: whisper_cpp.py
dist/Buzz dist/Buzz.app: buzz/whisper_cpp.py
pyinstaller --noconfirm Buzz.spec

version:
poetry version ${version}
echo "VERSION = \"${version}\"" > __version__.py
echo "VERSION = \"${version}\"" > buzz/__version__.py
sed -i "s/version=.*,/version=\'${version_escaped}\',/" Buzz.spec

CMAKE_FLAGS=
Expand All @@ -79,8 +79,8 @@ $(LIBWHISPER):
cp whisper.cpp/build/$(LIBWHISPER) . || true
cp whisper.cpp/build/bin/Debug/$(LIBWHISPER) . || true

whisper_cpp.py: $(LIBWHISPER)
ctypesgen ./whisper.cpp/whisper.h -l$(LIBWHISPER) -o whisper_cpp.py
buzz/whisper_cpp.py: $(LIBWHISPER)
ctypesgen ./whisper.cpp/whisper.h -l$(LIBWHISPER) -o buzz/whisper_cpp.py

staple_app_mac:
xcrun stapler staple ${mac_app_path}
Expand Down
Empty file added buzz/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions gui.py → buzz/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from requests import get
from whisper import tokenizer

from __version__ import VERSION
from transcriber import FileTranscriber, OutputFormat, RecordingTranscriber
from whispr import LOADED_WHISPER_DLL, Task
from model_loader import ModelLoader
from .__version__ import VERSION
from .transcriber import FileTranscriber, OutputFormat, RecordingTranscriber
from .whispr import LOADED_WHISPER_DLL, Task
from .model_loader import ModelLoader

APP_NAME = 'Buzz'

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions transcriber.py → buzz/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import whisper
from sounddevice import PortAudioError

from conn import pipe_stderr, pipe_stdout
from whispr import Segment, Task, WhisperCpp, read_progress, whisper_cpp_params
from .conn import pipe_stderr, pipe_stdout
from .whispr import (Segment, Task, WhisperCpp, read_progress,
whisper_cpp_params)


class RecordingTranscriber:
Expand Down
2 changes: 1 addition & 1 deletion whispr.py → buzz/whispr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# the DLL in some envs is fixed.
LOADED_WHISPER_DLL = False
try:
import whisper_cpp
import buzz.whisper_cpp as whisper_cpp
LOADED_WHISPER_DLL = True
except ImportError:
logging.exception('')
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
level=logging.DEBUG,
format="[%(asctime)s] %(module)s.%(funcName)s:%(lineno)d %(levelname)s -> %(message)s")

from gui import Application
from buzz.gui import Application
app = Application()
sys.exit(app.exec())
Empty file added tests/__init__.py
Empty file.
11 changes: 6 additions & 5 deletions gui_test.py → tests/gui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import sounddevice
from PyQt6.QtCore import Qt

from gui import (Application, AudioDevicesComboBox,
DownloadModelProgressDialog, FileTranscriberWidget,
LanguagesComboBox, MainWindow, OutputFormatsComboBox, Quality, Settings, AboutDialog,
QualityComboBox, TranscriberProgressDialog)
from transcriber import OutputFormat
from buzz.gui import (AboutDialog, Application, AudioDevicesComboBox,
DownloadModelProgressDialog, FileTranscriberWidget,
LanguagesComboBox, MainWindow, OutputFormatsComboBox,
Quality, QualityComboBox, Settings,
TranscriberProgressDialog)
from buzz.transcriber import OutputFormat


class TestApplication:
Expand Down
9 changes: 4 additions & 5 deletions transcriber_test.py → tests/transcriber_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging
import os
import pathlib
import tempfile
import time

import pytest

from model_loader import ModelLoader
from transcriber import (FileTranscriber, OutputFormat, RecordingTranscriber,
to_timestamp)
from whispr import Task
from buzz.model_loader import ModelLoader
from buzz.transcriber import (FileTranscriber, OutputFormat,
RecordingTranscriber, to_timestamp)
from buzz.whispr import Task


def get_model_path(model_name: str, use_whisper_cpp: bool) -> str:
Expand Down

0 comments on commit f358809

Please sign in to comment.