Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,9 +35,19 @@ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
|
| 35 |
)
|
| 36 |
|
| 37 |
# Load lora (giving it a name makes it active when using the name in the prompt)
|
| 38 |
-
|
| 39 |
pipe.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
|
| 40 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
pipe.to(device)
|
| 42 |
|
| 43 |
# 📸 Edge detection function using OpenCV (Canny)
|
|
@@ -82,6 +92,11 @@ with gr.Blocks() as demo:
|
|
| 82 |
strength = gr.Slider(0.1, 1.0, value=0.8, label="Denoising Strength")
|
| 83 |
guidance = gr.Slider(1, 20, value=7.5, label="Guidance Scale (Creativity)")
|
| 84 |
controlnet_conditioning_scale = gr.Slider(0, 1, value=0.5, step=0.01, label="ControlNet Conditioning Scale")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
generate_button = gr.Button("Generate Styled Image")
|
| 87 |
|
|
@@ -89,12 +104,27 @@ with gr.Blocks() as demo:
|
|
| 89 |
edge_output = gr.Image(label="Edge Detected Image")
|
| 90 |
result_output = gr.Image(label="Generated Styled Image")
|
| 91 |
|
| 92 |
-
# 🔗 Button Action
|
| 93 |
generate_button.click(
|
| 94 |
fn=generate_image,
|
| 95 |
inputs=[prompt, input_image, low_threshold, high_threshold, strength, guidance, controlnet_conditioning_scale],
|
| 96 |
outputs=[edge_output, result_output]
|
| 97 |
)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
# 🚀 Launch the app
|
| 100 |
demo.launch()
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
# Load lora (giving it a name makes it active when using the name in the prompt)
|
| 38 |
+
pipe.load_lora_weights("ostris/ikea-instructions-lora-sdxl", weight_name="ikea_instructions_xl_v1_5.safetensors", adapter_name="ikea")
|
| 39 |
pipe.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
|
| 40 |
+
pipe.disable_lora()
|
| 41 |
+
|
| 42 |
+
def activate_ikea_lora():
|
| 43 |
+
pipe.set_adapters("ikea")
|
| 44 |
+
|
| 45 |
+
def activate_pixel_lora():
|
| 46 |
+
pipe.set_adapters("pixel")
|
| 47 |
+
|
| 48 |
+
def disable_loras():
|
| 49 |
+
pipe.disable_lora()
|
| 50 |
+
|
| 51 |
pipe.to(device)
|
| 52 |
|
| 53 |
# 📸 Edge detection function using OpenCV (Canny)
|
|
|
|
| 92 |
strength = gr.Slider(0.1, 1.0, value=0.8, label="Denoising Strength")
|
| 93 |
guidance = gr.Slider(1, 20, value=7.5, label="Guidance Scale (Creativity)")
|
| 94 |
controlnet_conditioning_scale = gr.Slider(0, 1, value=0.5, step=0.01, label="ControlNet Conditioning Scale")
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
ikea_lora_button = gr.Button("IKEA Instructions")
|
| 98 |
+
pixel_lora_button = gr.Button("Pixel Art")
|
| 99 |
+
disable_lora_button = gr.Button("Disable LoRas")
|
| 100 |
|
| 101 |
generate_button = gr.Button("Generate Styled Image")
|
| 102 |
|
|
|
|
| 104 |
edge_output = gr.Image(label="Edge Detected Image")
|
| 105 |
result_output = gr.Image(label="Generated Styled Image")
|
| 106 |
|
| 107 |
+
# 🔗 Generate Button Action
|
| 108 |
generate_button.click(
|
| 109 |
fn=generate_image,
|
| 110 |
inputs=[prompt, input_image, low_threshold, high_threshold, strength, guidance, controlnet_conditioning_scale],
|
| 111 |
outputs=[edge_output, result_output]
|
| 112 |
)
|
| 113 |
|
| 114 |
+
ikea_lora_button.click(
|
| 115 |
+
fn = activate_ikea_lora,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
pixel_lora_button.click(
|
| 119 |
+
fn = activate_pixel_lora,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
disable_lora_button.click(
|
| 123 |
+
fn = disable_loras,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
|
| 129 |
# 🚀 Launch the app
|
| 130 |
demo.launch()
|