Commit c61aea71 authored by dmMaze's avatar dmMaze
Browse files

Merge branch 'dev' of https://github.com/dmMaze/BallonsTranslator into dev

parents 71033411 d0a50418
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ from .ocr import OCR, OCRBase, OCRMIT32px, OCRMIT48pxCTC, MangaOCR
from .textdetector import TEXTDETECTORS, TextDetectorBase, ComicTextDetector
from .translators import TRANSLATORS, BaseTranslator
from .inpaint import INPAINTERS, InpainterBase, PatchmatchInpainter, AOTInpainter, LamaInpainterMPE
from .base import DEFAULT_DEVICE
from .base import DEFAULT_DEVICE, GPUINTENSIVE_SET

GET_VALID_TEXTDETECTORS = lambda : list(TEXTDETECTORS.module_dict.keys())
GET_VALID_TRANSLATORS = lambda : list(TRANSLATORS.module_dict.keys())
+7 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ from ..textdetector.textblock import TextBlock
from ..base import BaseModule, DEVICE_SELECTOR
from utils.registry import Registry
from utils.io_utils import text_is_empty
from utils.logger import logger as LOGGER

TRANSLATORS = Registry('translators')
register_translator = TRANSLATORS.register_module
@@ -152,7 +153,12 @@ class BaseTranslator(BaseModule):
            text_trans = self.text2textlist(text_trans)
            
        if is_list:
            try:
                assert len(text_trans) == len(text)
            except:
                LOGGER.error('This translator seems to messed up the translation which resulted in inconsistent translated line count.\n \
                             Set concate_text to False or change textblk_break in the source code may solve the problem.')
                raise
            # for ii, t in enumerate(text_trans):
            #     for callback in self._postprocess_hooks:
            #         text_trans[ii] = callback(t)
+10 −3
Original line number Diff line number Diff line
@@ -142,8 +142,15 @@ class GPTTranslator(BaseTranslator):
        else:
            return None

    def _assemble_prompts(self, from_lang: str, to_lang: str, queries: List[str]) -> List[str]:
    def _assemble_prompts(self, queries: List[str], from_lang: str = None, to_lang: str = None, max_tokens = None) -> List[str]:
        if from_lang is None:
            from_lang = self.lang_map[self.lang_source]
        if to_lang is None:
            to_lang = self.lang_map[self.lang_target]
            
        prompt = ''

        if max_tokens is None:
            max_tokens = self.max_tokens
        # return_prompt = self.params['return prompt']
        prompt_template = self.params['prompt template']['content'].format(to_lang=to_lang).rstrip()
@@ -200,7 +207,7 @@ class GPTTranslator(BaseTranslator):
        queries = src_list
        # return_prompt = self.params['return prompt']
        chat_sample = self.chat_sample
        for prompt, num_src in self._assemble_prompts(from_lang, to_lang, queries):
        for prompt, num_src in self._assemble_prompts(queries, from_lang, to_lang):
            ratelimit_attempt = 0
            retry_attempt = 0
            while True:
+7 −1
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ import json
import httpx
from langdetect import detect

from utils.logger import logger as LOGGER


deeplAPI = "https://www2.deepl.com/jsonrpc"
headers = {
@@ -179,10 +181,12 @@ class DeepLX(BaseTranslator):
    params: Dict = {
        'delay': 0.0,
    }
    concate_text = True
    
    def _setup_translator(self):
        self.lang_map['简体中文'] = 'zh'
        self.lang_map['日本語'] = 'ja'
        self.lang_map['English'] = 'EN-US'
        self.lang_map['English'] = 'en'
        self.lang_map['Français'] = 'fr'
        self.lang_map['Deutsch'] = 'de'
        self.lang_map['Italiano'] = 'it'
@@ -207,6 +211,7 @@ class DeepLX(BaseTranslator):
        self.lang_map['Indonesia'] = 'id'
        self.lang_map['украї́нська мо́ва'] = 'uk'
        self.lang_map['한국어'] = 'ko'
        self.textblk_break = '\n'

    def _translate(self, src_list: List[str]) -> List[str]:
        result = []
@@ -224,5 +229,6 @@ class DeepLX(BaseTranslator):
            #     t1 = e
            tl = translate(t,source,target)
            result.append(tl)
            
        return result 
    
+2 −2
Original line number Diff line number Diff line
from typing import List, Callable

from modules import GET_VALID_INPAINTERS, GET_VALID_TEXTDETECTORS, GET_VALID_TRANSLATORS, GET_VALID_OCR, \
    BaseTranslator, DEFAULT_DEVICE
    BaseTranslator, DEFAULT_DEVICE, GPUINTENSIVE_SET
from utils.logger import logger as LOGGER
from .stylewidgets import ConfigComboBox, NoBorderPushBtn, CustomComboBox
from .constants import CONFIG_FONTSIZE_CONTENT, CONFIG_COMBOBOX_MIDEAN, CONFIG_COMBOBOX_LONG, CONFIG_COMBOBOX_SHORT, CONFIG_COMBOBOX_HEIGHT
@@ -163,7 +163,7 @@ class ParamWidget(QWidget):
                    if param_key == 'device' and DEFAULT_DEVICE == 'cpu':
                        param_dict['select'] = 'cpu'
                        for ii, device in enumerate(param_dict['options']):
                            if device == 'cuda':
                            if device in GPUINTENSIVE_SET:
                                model = param_widget.model()
                                item = model.item(ii, 0)
                                item.setEnabled(False)
Loading