File size: 4,226 Bytes
74b9ce2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df76524
 
 
74b9ce2
df76524
74b9ce2
 
 
 
c066c94
8ebe4d8
c066c94
74b9ce2
 
 
 
 
2ccfab1
74b9ce2
2ccfab1
74b9ce2
2ccfab1
 
74b9ce2
 
 
 
 
 
 
 
 
 
 
 
 
 
8ebe4d8
 
 
74b9ce2
 
 
 
 
8ebe4d8
 
 
74b9ce2
 
 
 
 
9bc0b7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74b9ce2
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
from ppdiffusers import StableDiffusionPipeline

def generate_image(model, prompt, width, height, num_inference_steps, guidance_scale):

    if model == "shanshui_gen_style":
        pipe = StableDiffusionPipeline.from_pretrained("megemini/shanshui_gen_style", from_hf_hub=True)
    elif model == "shanshui_style":
        pipe = StableDiffusionPipeline.from_pretrained("megemini/shanshui_style", from_hf_hub=True)
    else:
        raise

    image = pipe(
        prompt, 
        num_inference_steps=100, 
        guidance_scale=7.5, 
        height=height, 
        width=width,).images[0]
    return image

demo = gr.Blocks()

with demo:
    gr.Markdown(
        r"""
        ### 当中国水墨山水遇上AIGC        
        """
    )
    
    gr.Markdown(
        r"""
        [【Hackathon】基于PaddleNLP PPDiffusers 训练 AIGC 趣味模型](https://github.com/PaddlePaddle/community/blob/master/hackthon_4th/%E3%80%90PaddlePaddle%20Hackathon%204%E3%80%91%20%E6%A8%A1%E5%9E%8B%E5%A5%97%E4%BB%B6%E5%BC%80%E6%BA%90%E8%B4%A1%E7%8C%AE%E4%BB%BB%E5%8A%A1%E5%90%88%E9%9B%86.md#no105%E5%9F%BA%E4%BA%8Epaddlenlp-ppdiffusers-%E8%AE%AD%E7%BB%83-aigc-%E8%B6%A3%E5%91%B3%E6%A8%A1%E5%9E%8B-)
        
        模型 👉 [shanshui_style](https://huggingface.co/megemini/shanshui_style) 可以生成水墨山水画。

        模型 👉 [shanshui_gen_style](https://huggingface.co/megemini/shanshui_gen_style) 可以生成水墨山水画的具像图片。
        """
    )
    with gr.Row():
        with gr.Column():
            with gr.Row():
                model = gr.Dropdown(["shanshui_gen_style", "shanshui_style"], label="Model")
            with gr.Row():
                prompt = gr.Textbox(label='Prompt')
            with gr.Row():
                width = gr.Slider(128, 768, value=512, step=8, label="Width")
                height = gr.Slider(128, 768, value=512, step=8, label="Height")
            with gr.Row():
                num_inference_steps = gr.Textbox(label='num inference steps')
                guidance_scale = gr.Textbox(label='guidance scale')
            with gr.Row():
                btn = gr.Button(value="Run")
        with gr.Column():
            with gr.Row():
                output = gr.Image()

    gr.Examples(
        [
            [
                "shanshui_gen_style",
                "A fantasy landscape in <shanshui-gen-style>",
                512,
                288,
                100,
                7.5,
            ],
            [
                "shanshui_style",
                "A fantasy landscape in <shanshui-style>",
                512,
                288,
                100,
                7.5,
            ],
        ],
        [model, prompt, width, height, num_inference_steps, guidance_scale]
    )
    
    gr.Markdown(
        r"""
        一些模型生成的图片:

        | Image | model | prompt |
        | - | - | - |
        | ![](https://huggingface.co/megemini/shanshui_style/resolve/main/img/shanshui_style_0.jpeg) | megemini/shanshui_style | A fantasy landscape in \<shanshui-style\> |
        | ![](https://huggingface.co/megemini/shanshui_style/resolve/main/img/shanshui_style_1.jpeg) | megemini/shanshui_style | A fantasy landscape in \<shanshui-style\> |
        | ![](https://huggingface.co/megemini/shanshui_style/resolve/main/img/shanshui_style_2.jpeg) | megemini/shanshui_style | A fantasy landscape in \<shanshui-style\> |
        | ![](https://huggingface.co/megemini/shanshui_gen_style/resolve/main/img/shanshui_gen_style_0.jpeg) | megemini/shanshui_gen_style | A fantasy landscape in \<shanshui-gen-style\> |
        | ![](https://huggingface.co/megemini/shanshui_gen_style/resolve/main/img/shanshui_gen_style_1.jpeg) | megemini/shanshui_gen_style | A fantasy landscape in \<shanshui-gen-style\> |
        | ![](https://huggingface.co/megemini/shanshui_gen_style/resolve/main/img/shanshui_gen_style_2.jpeg) | megemini/shanshui_gen_style | A fantasy landscape in \<shanshui-gen-style\> |
        """
    )

    btn.click(
        generate_image, 
        [model, prompt, width, height, num_inference_steps, guidance_scale], 
        output)



if __name__ == "__main__":
    demo.launch(debug=True)