zyddnys / manga-image-translator

Translate manga/image 一键翻译各类图片内文字 https://cotrans.touhou.ai/
https://cotrans.touhou.ai/
GNU General Public License v3.0
5.11k stars 527 forks source link

[Bug]: TypeError: 'type' object is not subscriptable #596

Open Tianci-King opened 6 months ago

Tianci-King commented 6 months ago

Issue

I've gone through the installation steps for dependencies as outlined in your readme document, yet I'm facing the issue
about "TypeError: 'type' object is not subscriptable" . I had installed all the requires , but it did not worked. My python version is 3.8.13. I would greatly appreciate your assistance !

iShot_2024-03-29_16 32 37

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/imagetranslator/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/imagetranslator/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/imagetranslator/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/Users/tiancy/project/manga-image-translator/manga_translator/__init__.py", line 7, in <module>
    from .manga_translator import *
  File "/Users/tiancy/project/manga-image-translator/manga_translator/manga_translator.py", line 23, in <module>
    from .args import DEFAULT_ARGS, translator_chain
  File "/Users/tiancy/project/manga-image-translator/manga_translator/args.py", line 8, in <module>
    from .translators import VALID_LANGUAGES, TRANSLATORS, TranslatorChain
  File "/Users/tiancy/project/manga-image-translator/manga_translator/translators/__init__.py", line 14, in <module>
    from .mbart50 import MBart50Translator
  File "/Users/tiancy/project/manga-image-translator/manga_translator/translators/mbart50.py", line 31, in <module>
    class MBart50Translator(OfflineTranslator):
  File "/Users/tiancy/project/manga-image-translator/manga_translator/translators/mbart50.py", line 79, in MBart50Translator
    async def _infer(self, from_lang: str, to_lang: str, queries: list[str]) -> list[str]:
TypeError: 'type' object is not subscriptable
grassroadsZ commented 6 months ago

`from typing import List

async def _infer(self, from_lang: str, to_lang: str, queries: List[str]) -> List[str]: if from_lang == 'auto': detected_lang = langid.classify('\n'.join(queries))[0] target_lang = self._map_detected_lang_to_translator(detected_lang)

    if target_lang == None:
        self.logger.warn('Could not detect language from over all sentence. Will try per sentence.')
    else:
        from_lang = target_lang

return [self._translate_sentence(from_lang, to_lang, query) for query in queries]

` this code can work

AI-confused commented 5 months ago

List[str] modify to List this can work

starise-wg commented 3 months ago

May I ask if this problem has been resolved? I also encountered the same error, 微信截图_20240612153225 - 副本 微信截图_20240612153324