Commit 755d1260 authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): remove useless lines

parent ee49640e
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ Overview:
"""
import json
from functools import lru_cache
from typing import Union, List, Optional, Tuple
from typing import Literal, Union, List, Optional, Tuple

import numpy as np
from PIL import Image
@@ -34,11 +34,6 @@ from huggingface_hub import hf_hub_download
from sklearn.cluster import DBSCAN, OPTICS
from tqdm.auto import tqdm

try:
    from typing import Literal
except (ModuleNotFoundError, ImportError):
    from typing_extensions import Literal

from ..data import MultiImagesTyping, load_images, ImageTyping
from ..utils import open_onnx_model

+2 −38
Original line number Diff line number Diff line
@@ -4,22 +4,15 @@ Overview:
"""
import math
import os.path
import warnings
from functools import lru_cache
from typing import Tuple, Optional
from typing import Literal, Tuple, Optional

import numpy as np
from PIL import Image
from emoji import emojize
from hbutils.system import TemporaryDirectory
from hbutils.testing import vpython
from scipy.ndimage import center_of_mass

try:
    from typing import Literal
except (ImportError, ModuleNotFoundError):
    from typing_extensions import Literal

from .align import align_maxsize
from .censor_ import BaseCensor, register_censor_method
from .squeeze import squeeze_with_transparency, _get_mask_of_transparency
@@ -403,38 +396,9 @@ class EmojiBasedCensor(BaseCensor):

            .. image:: censor_emoji.plot.py.svg
                :align: center

        .. warning::
            Due to compatibility issues with pilmoji library in Python 3.7, and the fact that
            Python 3.7 reached its end of life on June 27, 2023, custom emojis cannot be used in Python 3.7.
            To ensure that the code can still be executed, the :class:`ImageBasedCensor` with
            a pre-defined smiley face image will be used instead.
            When used, the values of the ``emoji`` and ``style`` parameters will be ignored.
        """
        return _get_native_emoji_censor(emoji, style, self.rotate, self.step) \
            .censor_area(image, area, ratio_threshold, **kwargs)


if vpython >= '3.8':
register_censor_method('emoji', EmojiBasedCensor)

else:
    @lru_cache()
    def _py37_fallback():
        warnings.warn('Due to compatibility issues with the pilmoji library, '
                      'the emoji censor method is not supported in Python 3.7. '
                      'A pre-defined single emoji image will be used for rendering, '
                      'and the emoji and style parameters will be ignored.')


    class _Python37FallbackCensor(ImageBasedCensor):
        def __init__(self):
            ImageBasedCensor.__init__(self, [_get_file_in_censor_assets('emoji_censor.png')])

        def censor_area(self, image: Image.Image, area: Tuple[int, int, int, int], ratio_threshold: float = 0.5,
                        **kwargs) -> Image.Image:
            _py37_fallback()
            return ImageBasedCensor.censor_area(self, image, area, ratio_threshold, **kwargs)


    register_censor_method('emoji', _Python37FallbackCensor)
+1 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ Overview:
        your image source or preprocess them using SCUNet.
"""
from functools import lru_cache
from typing import Literal

import numpy as np
from PIL import Image
@@ -24,11 +25,6 @@ from huggingface_hub import hf_hub_download
from ..data import ImageTyping, load_image
from ..utils import open_onnx_model, area_batch_run

try:
    from typing import Literal
except (ImportError, ModuleNotFoundError):
    from typing_extensions import Literal

NafNetModelTyping = Literal['REDS', 'GoPro', 'SIDD']


+1 −5
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ Overview:

"""
from functools import lru_cache
from typing import Literal

import numpy as np
from PIL import Image
@@ -20,11 +21,6 @@ from huggingface_hub import hf_hub_download
from ..data import ImageTyping, load_image
from ..utils import open_onnx_model, area_batch_run

try:
    from typing import Literal
except (ImportError, ModuleNotFoundError):
    from typing_extensions import Literal

SCUNetModelTyping = Literal['GAN', 'PSNR']


+1 −6
Original line number Diff line number Diff line
import random
import re
from typing import Union, List, Mapping

try:
    from typing import Literal
except (ImportError, ModuleNotFoundError):
    from typing_extensions import Literal
from typing import Literal, Union, List, Mapping


def sort_tags(tags: Union[List[str], Mapping[str, float]],