weifeng-chen commited on
Commit
5905366
1 Parent(s): 7e31dbb

new gradio ui with examples

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -6,7 +6,6 @@ from diffusers import StableDiffusionPipeline
6
  device="cuda"
7
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
8
 
9
- # pipe_img2img = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, unet=unet).to(device)
10
  pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id).to(device)
11
 
12
  def resize(w_val,l_val,img):
@@ -20,12 +19,28 @@ def infer(prompt, guide, steps, width, height):
20
  image = output.images[0]
21
  return image
22
 
23
- gr.Interface(fn=infer, inputs=
24
- [
25
- # gr.Image(source="upload", type="filepath", label="原始图像"),
26
- gr.Textbox(label = '提示词(prompt)'),
27
- gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)'),
28
- gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)'),
29
- gr.Slider(256, 768, value = 512, step = 64, label = '宽度(width)'),
30
- gr.Slider(256, 768, value = 512, step = 64, label = '高度(height)'),
31
- ],outputs='image').queue(concurrency_count=10).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  device="cuda"
7
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
8
 
 
9
  pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id).to(device)
10
 
11
  def resize(w_val,l_val,img):
 
19
  image = output.images[0]
20
  return image
21
 
22
+ with gr.Blocks() as demo:
23
+ examples = [
24
+ ["飞流直下三千尺, 疑是银河落九天, 瀑布, 插画"],
25
+ ["东临碣石, 以观沧海, 波涛汹涌, 插画"],
26
+ ["孤帆远影碧空尽,惟见长江天际流,油画"],
27
+ ["女孩背影, 日落, 唯美插画"],
28
+ ]
29
+ with gr.Row():
30
+ with gr.Column(scale=2, ):
31
+ output = gr.Image(label = '输出(output)')
32
+
33
+ with gr.Column(scale=1, ):
34
+ guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
35
+ steps = gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)')
36
+ width = gr.Slider(256, 768, value = 512, step = 64, label = '宽度(width)')
37
+ height = gr.Slider(256, 768, value = 512, step = 64, label = '高度(height)')
38
+
39
+ prompt = gr.Textbox(label = '提示词(prompt)')
40
+ submit_btn = gr.Button("生成图片(Generate)").style(margin=False, rounded=(False, True, True, False), full_width=False,)
41
+
42
+ ex = gr.Examples(examples, fn=infer, inputs=[prompt, guide, steps, width, height], outputs=output)
43
+
44
+ submit_btn.click(fn = infer, inputs = [prompt, guide, steps, width, height], outputs = output)
45
+
46
+ demo.queue(concurrency_count=10).launch()