Spaces:
Runtime error
Runtime error
Commit
·
f55ad8a
1
Parent(s):
5600a85
bug fix
Browse files
app.py
CHANGED
|
@@ -17,18 +17,21 @@ pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=to
|
|
| 17 |
# pipe_inpaint = StableDiffusionInpaintPipeline(**pipe_text2img.components) # not work
|
| 18 |
pipe_img2img = StableDiffusionImg2ImgPipeline(**pipe_text2img.components).to(device)
|
| 19 |
|
| 20 |
-
def infer_text2img(prompt, width, height):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
def
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
image = output.images[0]
|
| 29 |
return image
|
| 30 |
|
| 31 |
-
def infer_inpaint(prompt, width, height, image_in):
|
| 32 |
init_image = image_in["image"].convert("RGB").resize((width, height))
|
| 33 |
mask = image_in["mask"].convert("RGB").resize((width, height))
|
| 34 |
|
|
@@ -48,12 +51,14 @@ with gr.Blocks() as demo:
|
|
| 48 |
]
|
| 49 |
with gr.Row():
|
| 50 |
with gr.Column(scale=1, ):
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
prompt = gr.Textbox(label = '提示词(prompt)')
|
| 58 |
submit_btn = gr.Button("生成图像(Generate)")
|
| 59 |
|
|
@@ -66,10 +71,7 @@ with gr.Blocks() as demo:
|
|
| 66 |
# inpaint_btn = gr.Button("图像编辑(Inpaint)")
|
| 67 |
# img2img_prompt = gr.Textbox(label = '提示词(prompt)')
|
| 68 |
# img2img_btn = gr.Button("图像编辑(Inpaint)")
|
| 69 |
-
|
| 70 |
-
submit_btn.click(fn = infer_img2img, inputs = [prompt, width, height, image_in, strength], outputs = image_out)
|
| 71 |
-
else:
|
| 72 |
-
submit_btn.click(fn = infer_text2img, inputs = [prompt, width, height], outputs = image_out)
|
| 73 |
# inpaint_btn.click(fn = infer_inpaint, inputs = [inpaint_prompt, width, height, image_in], outputs = image_out)
|
| 74 |
# img2img_btn.click(fn = infer_img2img, inputs = [img2img_prompt, width, height, image_in], outputs = image_out)
|
| 75 |
demo.queue(concurrency_count=10).launch()
|
|
|
|
| 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]
|
| 23 |
+
# return image
|
| 24 |
|
| 25 |
+
def infer_text2img(prompt, guide, steps, width, height, image_in, strength):
|
| 26 |
+
if image_in is not None:
|
| 27 |
+
init_image = image_in.convert("RGB").resize((width, height))
|
| 28 |
+
output = pipe_img2img(prompt, init_image=init_image, strength=strength, width=width, height=height, guidance_scale=guide, num_inference_steps=steps)
|
| 29 |
+
else:
|
| 30 |
+
output = pipe_text2img(prompt, width=width, height=height, guidance_scale=guide, num_inference_steps=steps,)
|
| 31 |
image = output.images[0]
|
| 32 |
return image
|
| 33 |
|
| 34 |
+
def infer_inpaint(prompt, guide, steps, width, height, image_in):
|
| 35 |
init_image = image_in["image"].convert("RGB").resize((width, height))
|
| 36 |
mask = image_in["mask"].convert("RGB").resize((width, height))
|
| 37 |
|
|
|
|
| 51 |
]
|
| 52 |
with gr.Row():
|
| 53 |
with gr.Column(scale=1, ):
|
| 54 |
+
with gr.Row(scale=0.5, ):
|
| 55 |
+
image_in = gr.Image(source='upload', elem_id="image_upload", type="pil", label="参考图")
|
| 56 |
+
with gr.Row(scale=0.5, ):
|
| 57 |
+
guide = gr.Slider(2, 15, value = 7, label = '文本引导强度(guidance scale)')
|
| 58 |
+
steps = gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)')
|
| 59 |
+
width = gr.Slider(256, 768, value = 512, step = 64, label = '宽度(width)')
|
| 60 |
+
height = gr.Slider(256, 768, value = 512, step = 64, label = '高度(height)')
|
| 61 |
+
strength = gr.Slider(0, 1.0, value = 0.8, step = 0.05, label = '参考图改变程度(strength)')
|
| 62 |
prompt = gr.Textbox(label = '提示词(prompt)')
|
| 63 |
submit_btn = gr.Button("生成图像(Generate)")
|
| 64 |
|
|
|
|
| 71 |
# inpaint_btn = gr.Button("图像编辑(Inpaint)")
|
| 72 |
# img2img_prompt = gr.Textbox(label = '提示词(prompt)')
|
| 73 |
# img2img_btn = gr.Button("图像编辑(Inpaint)")
|
| 74 |
+
submit_btn.click(fn = infer_text2img, inputs = [prompt, guide, steps, width, height, image_in, strength], outputs = image_out)
|
|
|
|
|
|
|
|
|
|
| 75 |
# inpaint_btn.click(fn = infer_inpaint, inputs = [inpaint_prompt, width, height, image_in], outputs = image_out)
|
| 76 |
# img2img_btn.click(fn = infer_img2img, inputs = [img2img_prompt, width, height, image_in], outputs = image_out)
|
| 77 |
demo.queue(concurrency_count=10).launch()
|