Skip to content

Commit

Permalink
Make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
deeplow committed Feb 8, 2023
1 parent 3b5c0af commit 59be377
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
3 changes: 1 addition & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import subprocess
from pathlib import Path

import pytest

import dangerzone.util as util
import pytest

VERSION_FILE_NAME = "version.txt"

Expand Down
38 changes: 22 additions & 16 deletions whisperzone/converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import pipes
import platform
import re
import shutil
Expand All @@ -8,7 +9,6 @@
import time
from datetime import datetime
from typing import Callable, Optional, Tuple
import pipes

from colorama import Fore, Style

Expand Down Expand Up @@ -38,15 +38,15 @@ def transcribe(
) -> bool:

args = [
"whisper",
document.input_filename,
"--language",
language,
"--model",
model,
"--output_format",
output_format
]
"whisper",
document.input_filename,
"--language",
language,
"--model",
model,
"--output_format",
output_format,
]
args_str = " ".join(pipes.quote(s) for s in args)
log.info("> " + args_str)

Expand Down Expand Up @@ -75,14 +75,16 @@ def transcribe(
def convert(
self,
document: Document,
language: str,
model: str,
output_format: str,
language: Optional[str] = "English",
model: Optional[str] = "small",
output_format: Optional[str] = "txt",
stdout_callback: Optional[Callable] = None,
) -> None:
document.mark_as_converting()

log.debug(f"transcribing {os.path.basename(document.input_filename)} in {language}")
log.debug(
f"transcribing {os.path.basename(document.input_filename)} in {language}"
)

# Get max num minutes
args = [
Expand All @@ -104,7 +106,9 @@ def convert(
self.duration = (end_time - self.start_time).seconds

try:
success = self.transcribe(document, language, model, output_format, stdout_callback)
success = self.transcribe(
document, language, model, output_format, stdout_callback
)
except Exception:
success = False
log.exception(
Expand All @@ -117,7 +121,9 @@ def convert(
else:
document.mark_as_failed()

def parse_progress(self, document: Document, line: str) -> Tuple[bool, str, int]:
def parse_progress(
self, document: Document, line: str
) -> None | Tuple[bool, str, int]:
"""
Parses a line returned by the container.
"""
Expand Down
4 changes: 3 additions & 1 deletion whisperzone/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def gui_main(filenames: Optional[List[str]]) -> bool:
os.environ["QT_MAC_WANTS_LAYER"] = "1"

# Make sure /usr/local/bin is in the path
os.environ["PATH"] = f"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:{os.environ['PATH']}"
os.environ[
"PATH"
] = f"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:{os.environ['PATH']}"

# Don't show ANSI colors from stdout output, to prevent terminal
# colors from breaking the macOS GUI app
Expand Down
31 changes: 17 additions & 14 deletions whisperzone/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import shutil
import subprocess
import tempfile
from abc import abstractmethod
import typing
from abc import abstractmethod
from multiprocessing.pool import ThreadPool
from typing import List, Optional

Expand Down Expand Up @@ -89,7 +89,6 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
self.show()

def waiting_finished(self) -> None:
self.dangerzone.is_waiting_finished = True
self.waiting_widget.hide()
self.content_widget.show()

Expand Down Expand Up @@ -378,7 +377,9 @@ def __init__(self, dangerzone: DangerzoneGui) -> None:
index = self.model_combobox.findText(self.dangerzone.settings.get("model"))
if index != -1:
self.model_combobox.setCurrentIndex(index)
index = self.output_format_combobox.findText(self.dangerzone.settings.get("output_format"))
index = self.output_format_combobox.findText(
self.dangerzone.settings.get("output_format")
)
if index != -1:
self.output_format_combobox.setCurrentIndex(index)

Expand All @@ -404,7 +405,9 @@ def start_button_clicked(self) -> None:
# Update settings
self.dangerzone.settings.set("language", self.lang_combobox.currentText())
self.dangerzone.settings.set("model", self.model_combobox.currentText())
self.dangerzone.settings.set("output_format", self.output_format_combobox.currentText())
self.dangerzone.settings.set(
"output_format", self.output_format_combobox.currentText()
)
self.dangerzone.settings.save()

# Start!
Expand All @@ -419,9 +422,9 @@ def __init__(
self,
dangerzone: DangerzoneGui,
document: Document,
language: str,
model: str,
output_format: str,
language: Optional[str],
model: Optional[str],
output_format: Optional[str],
) -> None:
super(ConvertTask, self).__init__()
self.document = document
Expand Down Expand Up @@ -471,22 +474,22 @@ def start_conversion(self) -> None:

for doc_widget in self.document_widgets:
task = ConvertTask(
self.dangerzone, doc_widget.document, self.get_language(), self.get_model(), self.get_output_format()
self.dangerzone,
doc_widget.document,
self.get_language(),
self.get_model(),
self.get_output_format(),
)
task.update.connect(doc_widget.update_progress)
task.finished.connect(doc_widget.all_done)
self.thread_pool.apply_async(task.convert_document)

def get_language(self) -> Optional[str]:
language = self.dangerzone.languages[
self.dangerzone.settings.get("language")
]
language = self.dangerzone.languages[self.dangerzone.settings.get("language")]
return language

def get_model(self) -> Optional[str]:
model = self.dangerzone.models[
self.dangerzone.settings.get("model")
]
model = self.dangerzone.models[self.dangerzone.settings.get("model")]
return model

def get_output_format(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion whisperzone/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, dangerzone: "DangerzoneCore") -> None:
self.default_settings: Dict[str, Any] = {
"language": "English",
"model": "base",
"output_format": "txt"
"output_format": "txt",
}

self.load()
Expand Down

0 comments on commit 59be377

Please sign in to comment.