2023-01-10 13:54:52 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiffusersStableDiffusionTest(unittest.TestCase, DemoCompatibilityCheck):
|
|
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
2023-01-11 21:49:58 +08:00
|
|
|
self.task = Tasks.text_to_image_synthesis
|
2023-01-10 13:54:52 +08:00
|
|
|
self.model_id = 'shadescript/stable-diffusion-2-1-dev'
|
|
|
|
|
|
|
|
|
|
test_input = 'a photo of an astronaut riding a horse on mars'
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run(self):
|
|
|
|
|
diffusers_pipeline = pipeline(task=self.task, model=self.model_id)
|
|
|
|
|
output = diffusers_pipeline(self.test_input, height=512, width=512)
|
2023-01-11 21:49:58 +08:00
|
|
|
output['output_img'][0].save('output.png')
|
|
|
|
|
print('Image saved to output.png')
|
2023-01-10 13:54:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|