Spaces:
Build error
Build error
Artiprocher
commited on
Commit
•
473b807
1
Parent(s):
ecf91ad
3x3
Browse files- README copy.md +0 -13
- app.py +14 -5
README copy.md
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: Pai Diffusion Large Zh
|
3 |
-
emoji: 📚
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: green
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.11.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from LdmZhPipeline import LDMZhTextToImagePipeline
|
3 |
import torch
|
|
|
|
|
4 |
|
5 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
6 |
model_id = "alibaba-pai/pai-diffusion-poem-large-zh"
|
@@ -9,9 +11,16 @@ pipe_text2img = LDMZhTextToImagePipeline.from_pretrained(model_id, use_auth_toke
|
|
9 |
pipe_text2img = pipe_text2img.to(device)
|
10 |
|
11 |
def infer_text2img(prompt, guide, steps):
|
12 |
-
output = pipe_text2img(prompt, guidance_scale=guide, num_inference_steps=steps
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
examples = [
|
@@ -21,9 +30,9 @@ with gr.Blocks() as demo:
|
|
21 |
]
|
22 |
with gr.Row():
|
23 |
with gr.Column(scale=1, ):
|
24 |
-
image_out = gr.Image(label = '输出(
|
25 |
with gr.Column(scale=1, ):
|
26 |
-
prompt = gr.Textbox(label = '提示词(
|
27 |
submit_btn = gr.Button("生成图像(Generate)")
|
28 |
with gr.Row(scale=0.5 ):
|
29 |
guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
|
|
|
1 |
import gradio as gr
|
2 |
from LdmZhPipeline import LDMZhTextToImagePipeline
|
3 |
import torch
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
model_id = "alibaba-pai/pai-diffusion-poem-large-zh"
|
|
|
11 |
pipe_text2img = pipe_text2img.to(device)
|
12 |
|
13 |
def infer_text2img(prompt, guide, steps):
|
14 |
+
output = pipe_text2img([prompt]*9, guidance_scale=guide, num_inference_steps=steps)
|
15 |
+
images = output.images
|
16 |
+
images = [np.array(images[i]) for i in range(9)]
|
17 |
+
images = np.concatenate([
|
18 |
+
np.concatenate(images[0:3], axis=0),
|
19 |
+
np.concatenate(images[3:6], axis=0),
|
20 |
+
np.concatenate(images[6:9], axis=0),
|
21 |
+
], axis=1)
|
22 |
+
images = Image.fromarray(images)
|
23 |
+
return images
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
examples = [
|
|
|
30 |
]
|
31 |
with gr.Row():
|
32 |
with gr.Column(scale=1, ):
|
33 |
+
image_out = gr.Image(label = '输出(output)')
|
34 |
with gr.Column(scale=1, ):
|
35 |
+
prompt = gr.Textbox(label = '提示词(prompt)')
|
36 |
submit_btn = gr.Button("生成图像(Generate)")
|
37 |
with gr.Row(scale=0.5 ):
|
38 |
guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
|