weifeng-chen commited on
Commit
cae18c0
1 Parent(s): 1218350
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -12,11 +12,11 @@ device="cuda"
12
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
13
 
14
  pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(device)
 
 
15
 
16
  # pipe_inpaint = StableDiffusionInpaintPipeline.from_pretrained(model_id).to(device) # work
17
  # pipe_inpaint = StableDiffusionInpaintPipeline(**pipe_text2img.components) # not work
18
- pipe_img2img = StableDiffusionImg2ImgPipeline(**pipe_text2img.components).to(device)
19
-
20
  # def infer_text2img(prompt, guide, steps, width, height):
21
  # output = pipe_text2img(prompt, width=width, height=height, guidance_scale=guide, num_inference_steps=steps,)
22
  # image = output.images[0]
@@ -51,21 +51,19 @@ with gr.Blocks() as demo:
51
  ]
52
  with gr.Row():
53
  with gr.Column(scale=1, ):
54
- with gr.Row(scale=0.5,):
55
- with gr.Column():
56
- image_in = gr.Image(source='upload', elem_id="image_upload", type="pil", label="参考图(ref)")
57
- with gr.Column():
58
- guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
59
- steps = gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)')
60
- width = gr.Slider(256, 768, value = 512, step = 64, label = '宽度(width)')
61
- height = gr.Slider(256, 768, value = 512, step = 64, label = '高度(height)')
62
- strength = gr.Slider(0, 1.0, value = 0.8, step = 0.05, label = '参考图改变程度(strength)')
63
  prompt = gr.Textbox(label = '提示词(prompt)')
64
  submit_btn = gr.Button("生成图像(Generate)")
65
-
66
- with gr.Column(scale=1, ):
67
- image_out = gr.Image(label = '输出(output)')
68
- ex = gr.Examples(examples, fn=infer_text2img, inputs=[prompt, width, height], outputs=image_out)
 
 
 
 
69
  # with gr.Column(scale=1, ):
70
  # image_in = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload")
71
  # inpaint_prompt = gr.Textbox(label = '提示词(prompt)')
@@ -75,4 +73,4 @@ with gr.Blocks() as demo:
75
  submit_btn.click(fn = infer_text2img, inputs = [prompt, guide, steps, width, height, image_in, strength], outputs = image_out)
76
  # inpaint_btn.click(fn = infer_inpaint, inputs = [inpaint_prompt, width, height, image_in], outputs = image_out)
77
  # img2img_btn.click(fn = infer_img2img, inputs = [img2img_prompt, width, height, image_in], outputs = image_out)
78
- demo.queue(concurrency_count=10).launch()
 
12
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
13
 
14
  pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(device)
15
+ pipe_img2img = StableDiffusionImg2ImgPipeline(**pipe_text2img.components).to(device)
16
+
17
 
18
  # pipe_inpaint = StableDiffusionInpaintPipeline.from_pretrained(model_id).to(device) # work
19
  # pipe_inpaint = StableDiffusionInpaintPipeline(**pipe_text2img.components) # not work
 
 
20
  # def infer_text2img(prompt, guide, steps, width, height):
21
  # output = pipe_text2img(prompt, width=width, height=height, guidance_scale=guide, num_inference_steps=steps,)
22
  # image = output.images[0]
 
51
  ]
52
  with gr.Row():
53
  with gr.Column(scale=1, ):
54
+ image_out = gr.Image(label = '输出(output)')
55
+ with gr.Column(scale=1, ):
56
+ image_in = gr.Image(source='upload', elem_id="image_upload", type="pil", label="参考图(非必须)(ref)")
 
 
 
 
 
 
57
  prompt = gr.Textbox(label = '提示词(prompt)')
58
  submit_btn = gr.Button("生成图像(Generate)")
59
+ with gr.Row(scale=0.5 ):
60
+ guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
61
+ steps = gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)')
62
+ width = gr.Slider(256, 768, value = 512, step = 64, label = '宽度(width)')
63
+ height = gr.Slider(256, 768, value = 512, step = 64, label = '高度(height)')
64
+ strength = gr.Slider(0, 1.0, value = 0.8, step = 0.05, label = '参考图改变程度(strength)')
65
+ ex = gr.Examples(examples, fn=infer_text2img, inputs=[prompt, guide, steps, width, height], outputs=image_out)
66
+
67
  # with gr.Column(scale=1, ):
68
  # image_in = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload")
69
  # inpaint_prompt = gr.Textbox(label = '提示词(prompt)')
 
73
  submit_btn.click(fn = infer_text2img, inputs = [prompt, guide, steps, width, height, image_in, strength], outputs = image_out)
74
  # inpaint_btn.click(fn = infer_inpaint, inputs = [inpaint_prompt, width, height, image_in], outputs = image_out)
75
  # img2img_btn.click(fn = infer_img2img, inputs = [img2img_prompt, width, height, image_in], outputs = image_out)
76
+ demo.queue(concurrency_count=16).launch()