2022-07-04 10:28:38 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
2022-07-27 17:29:16 +08:00
|
|
|
from modelscope.pipelines import pipeline
|
2022-07-04 10:28:38 +08:00
|
|
|
from modelscope.utils.constant import Tasks
|
2022-09-08 14:08:51 +08:00
|
|
|
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
2022-07-04 10:28:38 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
class TranslationTest(unittest.TestCase, DemoCompatibilityCheck):
|
|
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.translation
|
|
|
|
|
self.model_id = 'damo/nlp_csanmt_translation_zh2en'
|
2022-07-04 10:28:38 +08:00
|
|
|
|
2022-08-06 23:17:21 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-08-30 22:08:27 +08:00
|
|
|
def test_run_with_model_name_for_zh2en(self):
|
|
|
|
|
inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task, model=self.model_id)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_for_en2zh(self):
|
|
|
|
|
model_id = 'damo/nlp_csanmt_translation_en2zh'
|
|
|
|
|
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task, model=model_id)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
2022-07-04 10:28:38 +08:00
|
|
|
|
2022-08-05 23:48:46 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_default_model(self):
|
2022-08-30 22:08:27 +08:00
|
|
|
inputs = '声明补充说,沃伦的同事都深感震惊,并且希望他能够投案自首。'
|
2022-09-08 14:08:51 +08:00
|
|
|
pipeline_ins = pipeline(self.task)
|
2022-08-30 22:08:27 +08:00
|
|
|
print(pipeline_ins(input=inputs))
|
2022-08-05 23:48:46 +08:00
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_demo_compatibility(self):
|
|
|
|
|
self.compatibility_check()
|
|
|
|
|
|
2022-07-04 10:28:38 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|