2023-01-10 13:54:52 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
2023-01-15 13:30:10 +00:00
|
|
|
import cv2
|
|
|
|
|
|
2023-01-10 13:54:52 +08:00
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-14 23:41:40 +08:00
|
|
|
class DiffusersStableDiffusionTest(unittest.TestCase):
|
2023-01-10 13:54:52 +08:00
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
2023-06-21 10:22:06 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
2023-01-10 13:54:52 +08:00
|
|
|
def test_run(self):
|
|
|
|
|
diffusers_pipeline = pipeline(task=self.task, model=self.model_id)
|
2023-01-15 13:30:10 +00:00
|
|
|
output = diffusers_pipeline({
|
2023-06-28 20:10:28 +08:00
|
|
|
'text': self.test_input,
|
2023-01-15 13:30:10 +00:00
|
|
|
'height': 512,
|
|
|
|
|
'width': 512
|
|
|
|
|
})
|
|
|
|
|
cv2.imwrite('output.png', output['output_imgs'][0])
|
2023-01-11 21:49:58 +08:00
|
|
|
print('Image saved to output.png')
|
2023-01-10 13:54:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|