Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from diffusers import AutoPipelineForText2Image, AutoencoderKL
|
| 3 |
from diffusers.utils import load_image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
|
|
|
| 7 |
text_pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True).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 |
ip.thumbnail((1024, 1024))
|
|
@@ -28,6 +33,27 @@ def text_to_image(ip, prompt, neg_prompt, width, height, ip_scale, strength, gui
|
|
| 28 |
return images[0]
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("""
|
| 33 |
# IP-Adapter Playground
|
|
@@ -62,5 +88,6 @@ with gr.Blocks() as demo:
|
|
| 62 |
steps_slider = gr.Slider(50, 100, value=75, step=1, label="Steps")
|
| 63 |
|
| 64 |
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)
|
|
|
|
| 65 |
|
| 66 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image, AutoencoderKL
|
| 3 |
from diffusers.utils import load_image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 7 |
+
|
| 8 |
text_pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to("cuda")
|
| 9 |
text_pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
| 10 |
text_pipeline.set_ip_adapter_scale(0.6)
|
| 11 |
|
| 12 |
+
image_pipeline = AutoPipelineForImage2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to("cuda")
|
| 13 |
+
image_pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
| 14 |
+
image_pipeline.set_ip_adapter_scale(0.6)
|
| 15 |
+
|
| 16 |
|
| 17 |
def text_to_image(ip, prompt, neg_prompt, width, height, ip_scale, strength, guidance, steps):
|
| 18 |
ip.thumbnail((1024, 1024))
|
|
|
|
| 33 |
return images[0]
|
| 34 |
|
| 35 |
|
| 36 |
+
def image_to_image(ip, image, prompt, neg_prompt, width, height, ip_scale, strength, guidance, steps):
|
| 37 |
+
ip.thumbnail((1024, 1024))
|
| 38 |
+
image.thumbnail((1024, 1024))
|
| 39 |
+
|
| 40 |
+
image_pipeline.set_ip_adapter_scale(ip_scale)
|
| 41 |
+
|
| 42 |
+
images = image_pipeline(
|
| 43 |
+
prompt=prompt,
|
| 44 |
+
image=image,
|
| 45 |
+
ip_adapter_image=ip,
|
| 46 |
+
negative_prompt=neg_prompt,
|
| 47 |
+
width=width,
|
| 48 |
+
height=height,
|
| 49 |
+
strength=strength,
|
| 50 |
+
guidance_scale=guidance,
|
| 51 |
+
num_inference_steps=steps,
|
| 52 |
+
).images
|
| 53 |
+
|
| 54 |
+
return images[0]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.Markdown("""
|
| 59 |
# IP-Adapter Playground
|
|
|
|
| 88 |
steps_slider = gr.Slider(50, 100, value=75, step=1, label="Steps")
|
| 89 |
|
| 90 |
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)
|
| 91 |
+
image_button.click(image_to_image, inputs=[image_ip, image_image, image_prompt, neg_prompt, width_slider, height_slider, ip_scale_slider, strength_slider, guidance_slider, steps_slider], outputs=output_image)
|
| 92 |
|
| 93 |
demo.launch()
|