File size: 1,499 Bytes
81c68e0
e82be26
81c68e0
473b807
81c68e0
034660a
e82be26
 
8a8b21d
81c68e0
 
e82be26
 
81c68e0
 
 
e82be26
 
 
81c68e0
 
2dfd9c6
473b807
81c68e0
473b807
81c68e0
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch
from PIL import Image

model_id = "alibaba-pai/pai-diffusion-artist-large-zh"
pipe = StableDiffusionPipeline.from_pretrained(model_id)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cpu")

def infer_text2img(prompt, guide, steps):
    image = pipe([prompt], guidance_scale=guide, num_inference_steps=steps).images[0]
    return image

with gr.Blocks() as demo:
    examples = [
                ["草地上的帐篷,背景是山脉"], 
                ["卧室里有一张床和一张桌子"], 
                ["雾蒙蒙的日出在湖面上"],
                ]
    with gr.Row():
        with gr.Column(scale=1, ):
            image_out = gr.Image(label = '输出(output)')
        with gr.Column(scale=1, ):
            prompt = gr.Textbox(label = '提示词(prompt)')
            submit_btn = gr.Button("生成图像(Generate)")
            with gr.Row(scale=0.5 ):
                guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
                steps = gr.Slider(10, 50, value = 20, step = 1, label = '迭代次数(inference steps)')
                ex = gr.Examples(examples, fn=infer_text2img, inputs=[prompt, guide, steps], outputs=image_out)
        submit_btn.click(fn = infer_text2img, inputs = [prompt, guide, steps], outputs = image_out)

demo.queue(concurrency_count=1, max_size=8).launch()