Skip to content

Commit

Permalink
Fix terminal value in .desktop file (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Jun 17, 2023
1 parent 1b13a36 commit 530bf28
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 257 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ jobs:
submodules: recursive
- uses: snapcore/action-build@v1
id: snapcraft
# - uses: snapcore/action-publish@v1
# env:
# SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
# with:
# snap: ${{ steps.snapcraft.outputs.snap }}
# release: edge
- run: |
sudo snap install --devmode *.snap
# - uses: snapcore/action-publish@v1
# env:
# SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
# with:
# snap: ${{ steps.snapcraft.outputs.snap }}
# release: edge
- uses: actions/upload-artifact@v3
with:
name: snap
Expand Down
2 changes: 1 addition & 1 deletion buzz.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Exec=/opt/buzz/Buzz

Icon=buzz

Terminal=False
Terminal=false
Empty file added buzz/__init__.py
Empty file.
130 changes: 130 additions & 0 deletions buzz/file_transcriber_queue_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import datetime
import logging
import multiprocessing
import queue
from typing import Optional, Tuple, List

from PyQt6.QtCore import QObject, QThread, pyqtSignal, pyqtSlot

from buzz.model_loader import ModelType
from buzz.transcriber import FileTranscriptionTask, FileTranscriber, WhisperCppFileTranscriber, \
OpenAIWhisperAPIFileTranscriber, WhisperFileTranscriber, Segment


class FileTranscriberQueueWorker(QObject):
tasks_queue: multiprocessing.Queue
current_task: Optional[FileTranscriptionTask] = None
current_transcriber: Optional[FileTranscriber] = None
current_transcriber_thread: Optional[QThread] = None
task_updated = pyqtSignal(FileTranscriptionTask)
completed = pyqtSignal()

def __init__(self, parent: Optional[QObject] = None):
super().__init__(parent)
self.tasks_queue = queue.Queue()
self.canceled_tasks = set()

@pyqtSlot()
def run(self):
logging.debug('Waiting for next transcription task')

# Get next non-canceled task from queue
while True:
self.current_task: Optional[FileTranscriptionTask] = self.tasks_queue.get()

# Stop listening when a "None" task is received
if self.current_task is None:
self.completed.emit()
return

if self.current_task.id in self.canceled_tasks:
continue

break

logging.debug('Starting next transcription task')

model_type = self.current_task.transcription_options.model.model_type
if model_type == ModelType.WHISPER_CPP:
self.current_transcriber = WhisperCppFileTranscriber(
task=self.current_task)
elif model_type == ModelType.OPEN_AI_WHISPER_API:
self.current_transcriber = OpenAIWhisperAPIFileTranscriber(task=self.current_task)
elif model_type == ModelType.HUGGING_FACE or \
model_type == ModelType.WHISPER or \
model_type == ModelType.FASTER_WHISPER:
self.current_transcriber = WhisperFileTranscriber(task=self.current_task)
else:
raise Exception(f'Unknown model type: {model_type}')

self.current_transcriber_thread = QThread(self)

self.current_transcriber.moveToThread(self.current_transcriber_thread)

self.current_transcriber_thread.started.connect(
self.current_transcriber.run)
self.current_transcriber.completed.connect(
self.current_transcriber_thread.quit)
self.current_transcriber.error.connect(
self.current_transcriber_thread.quit)

self.current_transcriber.completed.connect(
self.current_transcriber.deleteLater)
self.current_transcriber.error.connect(
self.current_transcriber.deleteLater)
self.current_transcriber_thread.finished.connect(
self.current_transcriber_thread.deleteLater)

self.current_transcriber.progress.connect(self.on_task_progress)
self.current_transcriber.error.connect(self.on_task_error)

self.current_transcriber.completed.connect(self.on_task_completed)

# Wait for next item on the queue
self.current_transcriber.error.connect(self.run)
self.current_transcriber.completed.connect(self.run)

self.current_task.started_at = datetime.datetime.now()
self.current_transcriber_thread.start()

def add_task(self, task: FileTranscriptionTask):
if task.queued_at is None:
task.queued_at = datetime.datetime.now()

self.tasks_queue.put(task)
task.status = FileTranscriptionTask.Status.QUEUED
self.task_updated.emit(task)

def cancel_task(self, task_id: int):
self.canceled_tasks.add(task_id)

if self.current_task.id == task_id:
if self.current_transcriber is not None:
self.current_transcriber.stop()

@pyqtSlot(Exception)
def on_task_error(self, error: Exception):
if self.current_task is not None and self.current_task.id not in self.canceled_tasks:
self.current_task.status = FileTranscriptionTask.Status.FAILED
self.current_task.error = str(error)
self.task_updated.emit(self.current_task)

@pyqtSlot(tuple)
def on_task_progress(self, progress: Tuple[int, int]):
if self.current_task is not None:
self.current_task.status = FileTranscriptionTask.Status.IN_PROGRESS
self.current_task.fraction_completed = progress[0] / progress[1]
self.task_updated.emit(self.current_task)

@pyqtSlot(list)
def on_task_completed(self, segments: List[Segment]):
if self.current_task is not None:
self.current_task.status = FileTranscriptionTask.Status.COMPLETED
self.current_task.segments = segments
self.current_task.completed_at = datetime.datetime.now()
self.task_updated.emit(self.current_task)

def stop(self):
self.tasks_queue.put(None)
if self.current_transcriber is not None:
self.current_transcriber.stop()
3 changes: 2 additions & 1 deletion buzz/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
from .transcriber import (SUPPORTED_OUTPUT_FORMATS, FileTranscriptionOptions, OutputFormat,
Task,
TranscriptionOptions,
FileTranscriberQueueWorker, FileTranscriptionTask, RecordingTranscriber, LOADED_WHISPER_DLL,
FileTranscriptionTask, RecordingTranscriber, LOADED_WHISPER_DLL,
DEFAULT_WHISPER_TEMPERATURE, LANGUAGES)
from .file_transcriber_queue_worker import FileTranscriberQueueWorker
from .widgets.line_edit import LineEdit
from .widgets.model_download_progress_dialog import ModelDownloadProgressDialog
from .widgets.model_type_combo_box import ModelTypeComboBox
Expand Down
Loading

1 comment on commit 530bf28

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Windows'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 530bf28 Previous: 1b13a36 Ratio
tests/transcriber_benchmarks_test.py::test_should_transcribe_and_benchmark[Whisper.cpp - Tiny] 0.012957114925586467 iter/sec (stddev: 0.27920214578394054) 0.03626320411436627 iter/sec (stddev: 8.547927962532297) 2.80

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.