Skip to content

Commit

Permalink
Merge pull request #341 from jhj0517/feature/support-i18n
Browse files Browse the repository at this point in the history
Support localization
  • Loading branch information
jhj0517 authored Oct 20, 2024
2 parents 8dc115b + 84fd983 commit ed6e918
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 203 deletions.
430 changes: 230 additions & 200 deletions app.py

Large diffs are not rendered by default.

321 changes: 321 additions & 0 deletions configs/translation.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion modules/translation/deepl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gradio as gr

from modules.utils.paths import TRANSLATION_OUTPUT_DIR, DEFAULT_PARAMETERS_CONFIG_PATH
from modules.utils.constants import AUTOMATIC_DETECTION
from modules.utils.subtitle_manager import *
from modules.utils.files_manager import load_yaml, save_yaml

Expand Down Expand Up @@ -50,7 +51,7 @@
}

DEEPL_AVAILABLE_SOURCE_LANGS = {
'Automatic Detection': None,
AUTOMATIC_DETECTION: None,
'Bulgarian': 'BG',
'Czech': 'CS',
'Danish': 'DA',
Expand Down
3 changes: 3 additions & 0 deletions modules/utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from gradio_i18n import Translate, gettext as _

AUTOMATIC_DETECTION = _("Automatic Detection")
1 change: 1 addition & 0 deletions modules/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
UVR_MODELS_DIR = os.path.join(MODELS_DIR, "UVR", "MDX_Net_Models")
CONFIGS_DIR = os.path.join(WEBUI_DIR, "configs")
DEFAULT_PARAMETERS_CONFIG_PATH = os.path.join(CONFIGS_DIR, "default_parameters.yaml")
I18N_YAML_PATH = os.path.join(CONFIGS_DIR, "translation.yaml")
OUTPUT_DIR = os.path.join(WEBUI_DIR, "outputs")
TRANSLATION_OUTPUT_DIR = os.path.join(OUTPUT_DIR, "translations")
UVR_OUTPUT_DIR = os.path.join(OUTPUT_DIR, "UVR")
Expand Down
3 changes: 2 additions & 1 deletion modules/whisper/whisper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from modules.uvr.music_separator import MusicSeparator
from modules.utils.paths import (WHISPER_MODELS_DIR, DIARIZATION_MODELS_DIR, OUTPUT_DIR, DEFAULT_PARAMETERS_CONFIG_PATH,
UVR_MODELS_DIR)
from modules.utils.constants import AUTOMATIC_DETECTION
from modules.utils.subtitle_manager import get_srt, get_vtt, get_txt, write_file, safe_filename
from modules.utils.youtube_manager import get_ytdata, get_ytaudio
from modules.utils.files_manager import get_media_files, format_gradio_files, load_yaml, save_yaml
Expand Down Expand Up @@ -107,7 +108,7 @@ def run(self,

if params.lang is None:
pass
elif params.lang == "Automatic Detection":
elif params.lang == AUTOMATIC_DETECTION:
params.lang = None
else:
language_code_dict = {value: key for key, value in whisper.tokenizer.LANGUAGES.items()}
Expand Down
4 changes: 3 additions & 1 deletion modules/whisper/whisper_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Optional, Dict
import yaml

from modules.utils.constants import AUTOMATIC_DETECTION


@dataclass
class WhisperParameters:
Expand Down Expand Up @@ -306,7 +308,7 @@ def to_yaml(self) -> Dict:
data = {
"whisper": {
"model_size": self.model_size,
"lang": "Automatic Detection" if self.lang is None else self.lang,
"lang": AUTOMATIC_DETECTION.unwrap() if self.lang is None else self.lang,
"is_translate": self.is_translate,
"beam_size": self.beam_size,
"log_prob_threshold": self.log_prob_threshold,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ git+https://github.com/jhj0517/jhj0517-whisper.git
faster-whisper==1.0.3
transformers
gradio
git+https://github.com/jhj0517/gradio-i18n.git@fix/encoding-error
pytubefix
ruamel.yaml==0.18.6
pyannote.audio==3.3.1
Expand Down

0 comments on commit ed6e918

Please sign in to comment.