Commit 05e6ad96 authored by dmMaze's avatar dmMaze
Browse files

support automatic files downloading and move things around

parent bb616788
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ ballontranslator/gallery-dl
release
libs
icons
.btrans_cache

tmp.py
dummy_scripts.py
@@ -21,6 +22,7 @@ tmp
logs
ballontrans_pylibs_win
config/config.json
localtmp*

.vscode
.VSCodeCounter
+38 −30
Original line number Diff line number Diff line
@@ -140,6 +140,26 @@ def main():
    prepare_environment()

    from utils.logger import setup_logging, logger as LOGGER
    import utils.shared as shared
    from utils import config as program_config
    from utils.config import ProgramConfig

    shared.load_cache()

    try:
        config = ProgramConfig.load(shared.CONFIG_PATH)
    except Exception as e:
        LOGGER.exception(e)
        LOGGER.warning("Failed to load config file, using default config")
        config = ProgramConfig()
    program_config.pcfg = config


    from modules.prepare_local_files import prepare_local_files_forall

    
    # shared.load_cache()
    prepare_local_files_forall()

    if not args.qt_api in QT_APIS:
        os.environ['QT_API'] = 'pyqt6'
@@ -159,39 +179,27 @@ def main():

    LOGGER.info(f'QT_API: {API}, QT Version: {QT_VERSION}')

    from ui import constants as C
    from ui import config as program_config

    C.DEBUG = args.debug
    C.DEFAULT_DISPLAY_LANG = QLocale.system().name()
    C.USE_PYSIDE6 = API == 'pyside6'
    shared.DEBUG = args.debug
    shared.DEFAULT_DISPLAY_LANG = QLocale.system().name()
    shared.USE_PYSIDE6 = API == 'pyside6'
    if qtpy.API_NAME[-1] == '6':
        C.FLAG_QT6 = True
        shared.FLAG_QT6 = True
    else:
        C.FLAG_QT6 = False
        shared.FLAG_QT6 = False
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling
        QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) #use highdpi icons
        QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)

    os.chdir(C.PROGRAM_PATH)
    os.chdir(shared.PROGRAM_PATH)

    setup_logging(C.LOGGING_PATH)
    setup_logging(shared.LOGGING_PATH)

    load_modules()

    app = QApplication(sys.argv)
    from ui.config import ProgramConfig

    try:
        config = ProgramConfig.load(C.CONFIG_PATH)
    except Exception as e:
        LOGGER.exception(e)
        LOGGER.warning("Failed to load config file, using default config")
        config = ProgramConfig()
    program_config.pcfg = config

    lang = config.display_lang
    langp = osp.join(C.TRANSLATE_DIR, lang + '.qm')
    langp = osp.join(shared.TRANSLATE_DIR, lang + '.qm')
    if osp.exists(langp):
        translator = QTranslator()
        translator.load(lang, osp.dirname(osp.abspath(__file__)) + "/translate")
@@ -201,9 +209,9 @@ def main():
    LOGGER.info(f'set display language to {lang}')

    ps = QGuiApplication.primaryScreen()
    C.LDPI = ps.logicalDotsPerInch()
    C.SCREEN_W = ps.geometry().width()
    C.SCREEN_H = ps.geometry().height()
    shared.LDPI = ps.logicalDotsPerInch()
    shared.SCREEN_W = ps.geometry().width()
    shared.SCREEN_H = ps.geometry().height()

    # Fonts
    # Load custom fonts if they exist
@@ -213,14 +221,14 @@ def main():
    yahei = QFont('Microsoft YaHei UI')
    if yahei.exactMatch() and not sys.platform == 'darwin':
        QGuiApplication.setFont(yahei)
        C.DEFAULT_FONT_FAMILY = 'Microsoft YaHei UI'
        C.APP_DEFAULT_FONT = 'Microsoft YaHei UI'
        shared.DEFAULT_FONT_FAMILY = 'Microsoft YaHei UI'
        shared.APP_DEFAULT_FONT = 'Microsoft YaHei UI'
    else:
        app_font = app.font().family()
        C.DEFAULT_FONT_FAMILY = app_font
        C.APP_DEFAULT_FONT = app_font
        shared.DEFAULT_FONT_FAMILY = app_font
        shared.APP_DEFAULT_FONT = app_font

    C.APP_DEFAULT_FONT = app.font().defaultFamily()
    shared.APP_DEFAULT_FONT = app.font().defaultFamily()

    from ui.mainwindow import MainWindow

@@ -229,11 +237,11 @@ def main():
    BT = ballontrans
    BT.restart_signal.connect(restart)

    if C.SCREEN_W > 1707 and sys.platform == 'win32':   # higher than 2560 (1440p) / 1.5
    if shared.SCREEN_W > 1707 and sys.platform == 'win32':   # higher than 2560 (1440p) / 1.5
        # https://github.com/dmMaze/BallonsTranslator/issues/220
        BT.comicTransSplitter.setHandleWidth(10)

    ballontrans.setWindowIcon(QIcon(C.ICON_PATH))
    ballontrans.setWindowIcon(QIcon(shared.ICON_PATH))
    ballontrans.show()
    ballontrans.resetStyleSheet()
    sys.exit(app.exec())
+0 −15
Original line number Diff line number Diff line
@@ -72,25 +72,10 @@ calculate_hash() {
# Function to download and process files
download_and_process_files() {
    local files=(
        'inpainting.ckpt|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|no_zip||aot_inpainter.ckpt|data/models|878d541c68648969bc1b042a6e997f3a58e49b6c07c5636ad55130736977149f'
        'comictextdetector.pt|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|no_zip||comictextdetector.pt|data/models|1f90fa60aeeb1eb82e2ac1167a66bf139a8a61b8780acd351ead55268540cccb'
        'comictextdetector.pt.onnx|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|no_zip||comictextdetector.pt.onnx|data/models|1a86ace74961413cbd650002e7bb4dcec4980ffa21b2f19b86933372071d718f'
        'inpainting_lama_mpe.ckpt|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|no_zip||lama_mpe.ckpt|data/models|d625aa1b3e0d0408acfd6928aa84f005867aa8dbb9162480346a4e20660786cc'
        'README.md|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||README.md|data/models/manga-ocr-base|32f413afcc4295151e77d25202c5c5d81ef621b46f947da1c3bde13256dc0d5f'
        'config.json|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||config.json|data/models/manga-ocr-base|8c0e395de8fa699daaac21aee33a4ba9bd1309cfbff03147813d2a025f39f349'
        'preprocessor_config.json|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||preprocessor_config.json|data/models/manga-ocr-base|af4eb4d79cf61b47010fc0bc9352ee967579c417423b4917188d809b7e048948'
        'pytorch_model.bin|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||pytorch_model.bin|data/models/manga-ocr-base|c63e0bb5b3ff798c5991de18a8e0956c7ee6d1563aca6729029815eda6f5c2eb'
        'special_tokens_map.json|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||special_tokens_map.json|data/models/manga-ocr-base|303df45a03609e4ead04bc3dc1536d0ab19b5358db685b6f3da123d05ec200e3'
        'tokenizer_config.json|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||tokenizer_config.json|data/models/manga-ocr-base|d775ad1deac162dc56b84e9b8638f95ed8a1f263d0f56f4f40834e26e205e266'
        'vocab.txt|https://huggingface.co/kha-white/manga-ocr-base/resolve/main|no_zip||vocab.txt|data/models/manga-ocr-base|344fbb6b8bf18c57839e924e2c9365434697e0227fac00b88bb4899b78aa594d'
        'ocr.zip|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|zip|ocr.ckpt|mit32px_ocr.ckpt|data/models|d9f619a9dccce8ce88357d1b17d25f07806f225c033ea42c64e86c45446cfe71'
        'ocr-ctc.zip|https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3|zip|ocr-ctc.ckpt|mit48pxctc_ocr.ckpt|data/models|8b0837a24da5fde96c23ca47bb7abd590cd5b185c307e348c6e0b7238178ed89'
        'postag.zip|https://github.com/lancopku/pkuseg-python/releases/download/v0.0.16|zip|features.pkl|features.pkl|data/models/pkuseg/postag|17d734c186a0f6e76d15f4990e766a00eed5f72bea099575df23677435ee749d'
        'postag.zip|https://github.com/lancopku/pkuseg-python/releases/download/v0.0.16|zip|weights.npz|weights.npz|data/models/pkuseg/postag|2bbd53b366be82a1becedb4d29f76296b36ad7560b6a8c85d54054900336d59a'
        'spacy_ontonotes.zip|https://github.com/explosion/spacy-pkuseg/releases/download/v0.0.26|zip|features.msgpack|features.msgpack|data/models/pkuseg/spacy_ontonotes|fd4322482a7018b9bce9216173ae9d2848efe6d310b468bbb4383fb55c874a18'
        'spacy_ontonotes.zip|https://github.com/explosion/spacy-pkuseg/releases/download/v0.0.26|zip|weights.npz|weights.npz|data/models/pkuseg/spacy_ontonotes|5ada075eb25a854f71d6e6fa4e7d55e7be0ae049255b1f8f19d05c13b1b68c9e'
        'libopencv_world.4.4.0.dylib.zip|https://github.com/dmMaze/BallonsTranslator/files/12571658|zip|libopencv_world.4.4.0.dylib|libopencv_world.4.4.0.dylib|data/libs|58bc785e410389a473a2a130c3134f5721a25bc5456072cb8efd405bf132487e'
        'libpatchmatch_inpaint.dylib.zip|https://github.com/dmMaze/BallonsTranslator/files/12571660|zip|libpatchmatch_inpaint.dylib|libpatchmatch_inpaint.dylib|data/libs|3d318885b3f440af0d837c3716a055e31b98b8eb7e50d1b6142d3cdc46c04e75'
        )
        
    # Iterate through file information
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ class BaseModule:
    _preprocess_hooks: OrderedDict = None
    _postprocess_hooks: OrderedDict = None

    download_file_list: List = None
    download_file_on_load = False

    def __init__(self, **params) -> None:
        if params:
            if self.params is None:
+23 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import numpy as np
import cv2
from typing import Dict, List
from collections import OrderedDict
import sys

from utils.registry import Registry
from utils.textblock_mask import extract_ballon_mask
@@ -130,6 +131,16 @@ class OpenCVInpainter(InpainterBase):
@register_inpainter('patchmatch')
class PatchmatchInpainter(InpainterBase):

    if sys.platform == 'darwin':
        download_file_list = [{
                'url': 'https://github.com/dmMaze/PyPatchMatchInpaint/releases/download/v1.0/macos_arm64_patchmatch_libs.7z',
                'sha256_pre_calculated': ['843704ab096d3afd8709abe2a2c525ce3a836bb0a629ed1ee9b8f5cee9938310', '849ca84759385d410c9587d69690e668822a3fc376ce2219e583e7e0be5b5e9a'],
                'files': ['macos_libopencv_world.4.8.0.dylib', 'macos_libpatchmatch_inpaint.dylib'],
                'save_dir': 'data/libs',
                'archived_files': 'macos_patchmatch_libs.7z',
                'archive_sha256_pre_calculated': '9f332c888be0f160dbe9f6d6887eb698a302e62f4c102a0f24359c540d5858ea'
        }]

    def setup_inpainter(self):
        from . import patch_match
        self.inpaint_method = lambda img, mask, *args, **kwargs: patch_match.inpaint(img, mask, patch_size=3)
@@ -171,6 +182,12 @@ class AOTInpainter(InpainterBase):
    inpaint_size = 2048
    model: AOTGenerator = None

    download_file_list = [{
            'url': 'https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3/inpainting.ckpt',
            'sha256_pre_calculated': '878d541c68648969bc1b042a6e997f3a58e49b6c07c5636ad55130736977149f',
            'files': 'data/models/aot_inpainter.ckpt',
    }]

    def setup_inpainter(self):
        global AOTMODEL
        self.device = self.params['device']['select']
@@ -266,6 +283,12 @@ class LamaInpainterMPE(InpainterBase):
    device = DEFAULT_DEVICE
    inpaint_size = 2048

    download_file_list = [{
            'url': 'https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3/inpainting_lama_mpe.ckpt',
            'sha256_pre_calculated': 'd625aa1b3e0d0408acfd6928aa84f005867aa8dbb9162480346a4e20660786cc',
            'files': 'data/models/lama_mpe.ckpt',
    }]

    def moveToDevice(self, device: str):
        self.model.to(device)
        self.device = device
Loading