Skip to content

Commit e9f785b

Browse files
authored
update ppdiffusers pipelines (#4230)
1 parent 2c465df commit e9f785b

File tree

3 files changed

+389
-14
lines changed

3 files changed

+389
-14
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
17+
from ppdiffusers import DiffusionPipeline
18+
from ppdiffusers.utils import load_image
19+
20+
img_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/image_example_1.png"
21+
mask_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/mask_example_1.png"
22+
example_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/reference_example_1.jpeg"
23+
24+
init_image = load_image(img_url).resize((512, 512))
25+
mask_image = load_image(mask_url).resize((512, 512))
26+
example_image = load_image(example_url).resize((512, 512))
27+
28+
pipe = DiffusionPipeline.from_pretrained("Fantasy-Studio/Paint-by-Example")
29+
30+
# 使用fp16加快生成速度
31+
with paddle.amp.auto_cast(True):
32+
image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[0]
33+
image.save("paint_by_example_test.png")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from scipy.io.wavfile import write
17+
18+
from ppdiffusers import AudioDiffusionPipeline
19+
20+
# 加载模型和scheduler
21+
pipe = AudioDiffusionPipeline.from_pretrained("teticio/audio-diffusion-ddim-256")
22+
pipe.set_progress_bar_config(disable=None)
23+
generator = paddle.Generator().manual_seed(42)
24+
25+
output = pipe(generator=generator)
26+
audio = output.audios[0]
27+
image = output.images[0]
28+
29+
# 保存音频到本地
30+
for i, audio in enumerate(audio):
31+
write(f"audio_diffusion_test{i}.wav", pipe.mel.sample_rate, audio.transpose())
32+
33+
# 保存图片
34+
image.save("audio_diffusion_test.png")

0 commit comments

Comments
 (0)