Skip to content

Commit

Permalink
dev(narugo): remove useless lines
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Jan 2, 2024
1 parent ee49640 commit 755d126
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 60 deletions.
7 changes: 1 addition & 6 deletions imgutils/metrics/ccip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@
"""
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
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

Expand Down
40 changes: 2 additions & 38 deletions imgutils/operate/imgcensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
"""
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
Expand Down Expand Up @@ -403,38 +396,9 @@ def censor_area(self, image: Image.Image, area: Tuple[int, int, int, int],
.. 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)
register_censor_method('emoji', EmojiBasedCensor)
6 changes: 1 addition & 5 deletions imgutils/restore/nafnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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
Expand All @@ -24,11 +25,6 @@
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']


Expand Down
6 changes: 1 addition & 5 deletions imgutils/restore/scunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
from functools import lru_cache
from typing import Literal

import numpy as np
from PIL import Image
Expand All @@ -20,11 +21,6 @@
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']


Expand Down
7 changes: 1 addition & 6 deletions imgutils/tagging/order.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
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]],
Expand Down

0 comments on commit 755d126

Please sign in to comment.