megemini commited on
Commit
74b9ce2
1 Parent(s): 6ed800c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ppdiffusers import StableDiffusionPipeline
3
+
4
+ def generate_image(model, prompt, width, height, num_inference_steps, guidance_scale):
5
+
6
+ if model == "shanshui_gen_style":
7
+ pipe = StableDiffusionPipeline.from_pretrained("megemini/shanshui_gen_style", from_hf_hub=True)
8
+ elif model == "shanshui_style":
9
+ pipe = StableDiffusionPipeline.from_pretrained("megemini/shanshui_style", from_hf_hub=True)
10
+ else:
11
+ raise
12
+
13
+ image = pipe(
14
+ prompt,
15
+ num_inference_steps=100,
16
+ guidance_scale=7.5,
17
+ height=height,
18
+ width=width,).images[0]
19
+ return image
20
+
21
+ demo = gr.Blocks()
22
+
23
+ with demo:
24
+ gr.Markdown(
25
+ r"### 【Hackathon】基于PaddleNLP PPDiffusers 训练 AIGC 趣味模型"
26
+ )
27
+ gr.Markdown(
28
+ r"""
29
+ [【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-)
30
+
31
+
32
+ """
33
+ )
34
+ with gr.Row():
35
+ with gr.Column():
36
+ with gr.Row():
37
+ model = gr.Dropdown(["shanshui_gen_style", "shanshui_style"], label="Model", info="The model to generate image.")
38
+ with gr.Row():
39
+ prompt = gr.Textbox(label='prompt')
40
+ with gr.Row():
41
+ width = gr.Slider(128, 768, value=512, step=8, label="Width", info="The width of image.")
42
+ height = gr.Slider(128, 768, value=512, step=8, label="Height", info="The height of image.")
43
+ with gr.Row():
44
+ num_inference_steps = gr.Textbox(label='num inference steps')
45
+ guidance_scale = gr.Textbox(label='guidance scale')
46
+ with gr.Row():
47
+ btn = gr.Button(value="Run")
48
+ with gr.Column():
49
+ with gr.Row():
50
+ output = gr.Image()
51
+
52
+ gr.Examples(
53
+ [
54
+ [
55
+ "shanshui_gen_style",
56
+ "A fantasy landscape in <shanshui-gen-style>",
57
+ 512,
58
+ 288,
59
+ 100,
60
+ 7.5,
61
+ ],
62
+ [
63
+ "shanshui_style",
64
+ "A fantasy landscape in <shanshui-style>",
65
+ 512,
66
+ 288,
67
+ 100,
68
+ 7.5,
69
+ ],
70
+ ],
71
+ [model, prompt, width, height, num_inference_steps, guidance_scale]
72
+ )
73
+
74
+ btn.click(
75
+ generate_image,
76
+ [model, prompt, width, height, num_inference_steps, guidance_scale],
77
+ output)
78
+
79
+
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch(debug=True)