Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
with gr.Blocks() as demo:
|
4 |
gr.Markdown("""
|
@@ -8,20 +34,22 @@ with gr.Blocks() as demo:
|
|
8 |
""")
|
9 |
with gr.Row():
|
10 |
with gr.Tab("Text-to-Image"):
|
11 |
-
text_ip = gr.Image(label='IP-Adapter Image')
|
12 |
text_prompt = gr.Textbox(label='Prompt')
|
13 |
text_button = gr.Button("Generate")
|
14 |
with gr.Tab("Image-to-Image"):
|
15 |
-
image_ip = gr.Image(label='IP-Adapter Image')
|
16 |
-
image_image = gr.Image(label='Image')
|
17 |
image_prompt = gr.Textbox(label='Prompt')
|
18 |
image_button = gr.Button("Generate")
|
19 |
with gr.Tab("Inpainting"):
|
20 |
-
inpaint_ip = gr.Image(label='IP-Adapter Image')
|
21 |
inpaint_editor = gr.ImageEditor(label='Image + Mask')
|
22 |
inpaint_prompt = gr.Textbox(label='Prompt')
|
23 |
inpaint_button = gr.Button("Generate")
|
|
|
24 |
output_image = gr.Image(label='Result')
|
|
|
25 |
with gr.Accordion("Advanced Settings", open=False):
|
26 |
neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed, nsfw')
|
27 |
width_slider = gr.Slider(256, 1024, value=1024, label="Width")
|
@@ -30,6 +58,7 @@ with gr.Blocks() as demo:
|
|
30 |
strength_slider = gr.Slider(0.0, 1.0, value=0.7, label="Strength")
|
31 |
guidance_slider = gr.Slider(1.0, 15.0, value=7.5, label="Guidance")
|
32 |
steps_slider = gr.Slider(50, 100, value=75, label="Steps")
|
33 |
-
|
|
|
34 |
|
35 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
+
from diffusers.utils import load_image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
|
7 |
+
text_pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
|
8 |
+
text_pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
9 |
+
text_pipeline.set_ip_adapter_scale(0.6)
|
10 |
+
|
11 |
+
|
12 |
+
def text_to_image(ip, prompt, neg_prompt, width, height, ip_scale, strength, guidance, steps):
|
13 |
+
text_pipeline.set_ip_adapter_scale(ip_scale)
|
14 |
+
|
15 |
+
images = pipeline(
|
16 |
+
prompt=prompt,
|
17 |
+
ip_adapter_image=ip,
|
18 |
+
negative_prompt=neg_prompt,
|
19 |
+
width=width,
|
20 |
+
height=height,
|
21 |
+
strength=strength,
|
22 |
+
guidance_scale=guidance,
|
23 |
+
num_inference_steps=steps,
|
24 |
+
).images
|
25 |
+
|
26 |
+
return images[0]
|
27 |
+
|
28 |
|
29 |
with gr.Blocks() as demo:
|
30 |
gr.Markdown("""
|
|
|
34 |
""")
|
35 |
with gr.Row():
|
36 |
with gr.Tab("Text-to-Image"):
|
37 |
+
text_ip = gr.Image(label='IP-Adapter Image', type='pil')
|
38 |
text_prompt = gr.Textbox(label='Prompt')
|
39 |
text_button = gr.Button("Generate")
|
40 |
with gr.Tab("Image-to-Image"):
|
41 |
+
image_ip = gr.Image(label='IP-Adapter Image', type='pil')
|
42 |
+
image_image = gr.Image(label='Image', type='pil')
|
43 |
image_prompt = gr.Textbox(label='Prompt')
|
44 |
image_button = gr.Button("Generate")
|
45 |
with gr.Tab("Inpainting"):
|
46 |
+
inpaint_ip = gr.Image(label='IP-Adapter Image', type='pil')
|
47 |
inpaint_editor = gr.ImageEditor(label='Image + Mask')
|
48 |
inpaint_prompt = gr.Textbox(label='Prompt')
|
49 |
inpaint_button = gr.Button("Generate")
|
50 |
+
|
51 |
output_image = gr.Image(label='Result')
|
52 |
+
|
53 |
with gr.Accordion("Advanced Settings", open=False):
|
54 |
neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed, nsfw')
|
55 |
width_slider = gr.Slider(256, 1024, value=1024, label="Width")
|
|
|
58 |
strength_slider = gr.Slider(0.0, 1.0, value=0.7, label="Strength")
|
59 |
guidance_slider = gr.Slider(1.0, 15.0, value=7.5, label="Guidance")
|
60 |
steps_slider = gr.Slider(50, 100, value=75, label="Steps")
|
61 |
+
|
62 |
+
text_button.click(text_to_image, inputs=[text_ip, text_prompt, neg_prompt, width_slider, height_slider, ip_scale_slider, strength_slider, guidance_slider, steps_slider], outputs=output_image)
|
63 |
|
64 |
demo.launch()
|