Spaces:
Running
Running
jocoandonob
commited on
Commit
·
1e86eb1
1
Parent(s):
a97a155
Initial commitcq
Browse files- app.py +232 -207
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -60,217 +60,235 @@ def load_image_from_url(url):
|
|
| 60 |
return Image.open(io.BytesIO(response.content)).convert("RGB")
|
| 61 |
|
| 62 |
def generate_image(prompt, seed, num_steps, guidance_scale, eta):
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
def generate_community_image(prompt, model_name, seed, num_steps, guidance_scale, eta):
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
def generate_style_mix(prompt, seed, num_steps, guidance_scale, eta, style_weight):
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
def generate_controlnet(prompt, init_image, seed, num_steps, guidance_scale, eta, controlnet_scale):
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
def inpaint_image(prompt, init_image, mask_image, seed, num_steps, guidance_scale, eta, strength):
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
def generate_animation(prompt, seed, num_steps, guidance_scale, eta, num_frames, motion_scale):
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
# Create the Gradio interface
|
| 276 |
with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
@@ -291,13 +309,15 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 291 |
text_guidance = gr.Slider(minimum=0, maximum=1, value=0, label="Guidance Scale")
|
| 292 |
text_eta = gr.Slider(minimum=0, maximum=1, value=0.3, label="Eta")
|
| 293 |
text_button = gr.Button("Generate")
|
|
|
|
| 294 |
with gr.Column():
|
| 295 |
text_output = gr.Image(label="Generated Image")
|
| 296 |
|
| 297 |
text_button.click(
|
| 298 |
fn=generate_image,
|
| 299 |
inputs=[text_prompt, text_seed, text_steps, text_guidance, text_eta],
|
| 300 |
-
outputs=text_output
|
|
|
|
| 301 |
)
|
| 302 |
|
| 303 |
with gr.TabItem("Inpainting"):
|
|
@@ -318,6 +338,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 318 |
inpaint_button = gr.Button("Inpaint")
|
| 319 |
with gr.Column():
|
| 320 |
inpaint_output = gr.Image(label="Result (Original | Mask | Generated)")
|
|
|
|
| 321 |
|
| 322 |
inpaint_button.click(
|
| 323 |
fn=inpaint_image,
|
|
@@ -325,7 +346,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 325 |
inpaint_prompt, init_image, mask_image, inpaint_seed,
|
| 326 |
inpaint_steps, inpaint_guidance, inpaint_eta, inpaint_strength
|
| 327 |
],
|
| 328 |
-
outputs=inpaint_output
|
| 329 |
)
|
| 330 |
|
| 331 |
with gr.TabItem("Community Models"):
|
|
@@ -348,6 +369,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 348 |
community_button = gr.Button("Generate")
|
| 349 |
with gr.Column():
|
| 350 |
community_output = gr.Image(label="Generated Image")
|
|
|
|
| 351 |
|
| 352 |
community_button.click(
|
| 353 |
fn=generate_community_image,
|
|
@@ -355,7 +377,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 355 |
community_prompt, model_dropdown, community_seed,
|
| 356 |
community_steps, community_guidance, community_eta
|
| 357 |
],
|
| 358 |
-
outputs=community_output
|
| 359 |
)
|
| 360 |
|
| 361 |
with gr.TabItem("Style Mixing"):
|
|
@@ -374,6 +396,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 374 |
style_button = gr.Button("Generate")
|
| 375 |
with gr.Column():
|
| 376 |
style_output = gr.Image(label="Generated Image")
|
|
|
|
| 377 |
|
| 378 |
style_button.click(
|
| 379 |
fn=generate_style_mix,
|
|
@@ -381,7 +404,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 381 |
style_prompt, style_seed, style_steps,
|
| 382 |
style_guidance, style_eta, style_weight
|
| 383 |
],
|
| 384 |
-
outputs=style_output
|
| 385 |
)
|
| 386 |
|
| 387 |
with gr.TabItem("ControlNet"):
|
|
@@ -401,6 +424,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 401 |
control_button = gr.Button("Generate")
|
| 402 |
with gr.Column():
|
| 403 |
control_output = gr.Image(label="Result (Depth Map | Generated)")
|
|
|
|
| 404 |
|
| 405 |
control_button.click(
|
| 406 |
fn=generate_controlnet,
|
|
@@ -408,7 +432,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 408 |
control_prompt, control_image, control_seed,
|
| 409 |
control_steps, control_guidance, control_eta, control_scale
|
| 410 |
],
|
| 411 |
-
outputs=control_output
|
| 412 |
)
|
| 413 |
|
| 414 |
with gr.TabItem("Animation"):
|
|
@@ -428,6 +452,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 428 |
anim_button = gr.Button("Generate Animation")
|
| 429 |
with gr.Column():
|
| 430 |
anim_output = gr.Image(label="Generated Animation")
|
|
|
|
| 431 |
|
| 432 |
anim_button.click(
|
| 433 |
fn=generate_animation,
|
|
@@ -436,7 +461,7 @@ with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
| 436 |
anim_guidance, anim_eta, anim_frames,
|
| 437 |
anim_motion_scale
|
| 438 |
],
|
| 439 |
-
outputs=anim_output
|
| 440 |
)
|
| 441 |
|
| 442 |
if __name__ == "__main__":
|
|
|
|
| 60 |
return Image.open(io.BytesIO(response.content)).convert("RGB")
|
| 61 |
|
| 62 |
def generate_image(prompt, seed, num_steps, guidance_scale, eta):
|
| 63 |
+
try:
|
| 64 |
+
# Initialize the pipeline
|
| 65 |
+
base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 66 |
+
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
|
| 67 |
+
|
| 68 |
+
# Use CPU for inference
|
| 69 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 70 |
+
base_model_id,
|
| 71 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 72 |
+
)
|
| 73 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 74 |
+
|
| 75 |
+
# Load and fuse LoRA weights
|
| 76 |
+
pipe.load_lora_weights(tcd_lora_id)
|
| 77 |
+
pipe.fuse_lora()
|
| 78 |
+
|
| 79 |
+
# Generate the image
|
| 80 |
+
generator = torch.Generator().manual_seed(seed)
|
| 81 |
+
image = pipe(
|
| 82 |
+
prompt=prompt,
|
| 83 |
+
num_inference_steps=num_steps,
|
| 84 |
+
guidance_scale=guidance_scale,
|
| 85 |
+
eta=eta,
|
| 86 |
+
generator=generator,
|
| 87 |
+
).images[0]
|
| 88 |
+
|
| 89 |
+
return image, "Image generated successfully!"
|
| 90 |
+
except Exception as e:
|
| 91 |
+
return None, f"Error generating image: {str(e)}"
|
| 92 |
|
| 93 |
def generate_community_image(prompt, model_name, seed, num_steps, guidance_scale, eta):
|
| 94 |
+
try:
|
| 95 |
+
# Initialize the pipeline
|
| 96 |
+
base_model_id = AVAILABLE_MODELS[model_name]
|
| 97 |
+
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
|
| 98 |
+
|
| 99 |
+
# Use CPU for inference
|
| 100 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 101 |
+
base_model_id,
|
| 102 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 103 |
+
)
|
| 104 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 105 |
+
|
| 106 |
+
# Load and fuse LoRA weights
|
| 107 |
+
pipe.load_lora_weights(tcd_lora_id)
|
| 108 |
+
pipe.fuse_lora()
|
| 109 |
+
|
| 110 |
+
# Generate the image
|
| 111 |
+
generator = torch.Generator().manual_seed(seed)
|
| 112 |
+
image = pipe(
|
| 113 |
+
prompt=prompt,
|
| 114 |
+
num_inference_steps=num_steps,
|
| 115 |
+
guidance_scale=guidance_scale,
|
| 116 |
+
eta=eta,
|
| 117 |
+
generator=generator,
|
| 118 |
+
).images[0]
|
| 119 |
+
|
| 120 |
+
return image, "Image generated successfully!"
|
| 121 |
+
except Exception as e:
|
| 122 |
+
return None, f"Error generating image: {str(e)}"
|
| 123 |
|
| 124 |
def generate_style_mix(prompt, seed, num_steps, guidance_scale, eta, style_weight):
|
| 125 |
+
try:
|
| 126 |
+
# Initialize the pipeline
|
| 127 |
+
base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 128 |
+
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
|
| 129 |
+
styled_lora_id = "TheLastBen/Papercut_SDXL"
|
| 130 |
+
|
| 131 |
+
# Use CPU for inference
|
| 132 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 133 |
+
base_model_id,
|
| 134 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 135 |
+
)
|
| 136 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 137 |
+
|
| 138 |
+
# Load multiple LoRA weights
|
| 139 |
+
pipe.load_lora_weights(tcd_lora_id, adapter_name="tcd")
|
| 140 |
+
pipe.load_lora_weights(styled_lora_id, adapter_name="style")
|
| 141 |
+
|
| 142 |
+
# Set adapter weights
|
| 143 |
+
pipe.set_adapters(["tcd", "style"], adapter_weights=[1.0, style_weight])
|
| 144 |
+
|
| 145 |
+
# Generate the image
|
| 146 |
+
generator = torch.Generator().manual_seed(seed)
|
| 147 |
+
image = pipe(
|
| 148 |
+
prompt=prompt,
|
| 149 |
+
num_inference_steps=num_steps,
|
| 150 |
+
guidance_scale=guidance_scale,
|
| 151 |
+
eta=eta,
|
| 152 |
+
generator=generator,
|
| 153 |
+
).images[0]
|
| 154 |
+
|
| 155 |
+
return image, "Image generated successfully!"
|
| 156 |
+
except Exception as e:
|
| 157 |
+
return None, f"Error generating image: {str(e)}"
|
| 158 |
|
| 159 |
def generate_controlnet(prompt, init_image, seed, num_steps, guidance_scale, eta, controlnet_scale):
|
| 160 |
+
try:
|
| 161 |
+
# Initialize the pipeline
|
| 162 |
+
base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 163 |
+
controlnet_id = "diffusers/controlnet-depth-sdxl-1.0"
|
| 164 |
+
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
|
| 165 |
+
|
| 166 |
+
# Initialize ControlNet
|
| 167 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 168 |
+
controlnet_id,
|
| 169 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# Initialize pipeline
|
| 173 |
+
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
| 174 |
+
base_model_id,
|
| 175 |
+
controlnet=controlnet,
|
| 176 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 177 |
+
)
|
| 178 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 179 |
+
|
| 180 |
+
# Load and fuse LoRA weights
|
| 181 |
+
pipe.load_lora_weights(tcd_lora_id)
|
| 182 |
+
pipe.fuse_lora()
|
| 183 |
+
|
| 184 |
+
# Generate depth map
|
| 185 |
+
depth_image = get_depth_map(init_image)
|
| 186 |
+
|
| 187 |
+
# Generate the image
|
| 188 |
+
generator = torch.Generator().manual_seed(seed)
|
| 189 |
+
image = pipe(
|
| 190 |
+
prompt=prompt,
|
| 191 |
+
image=depth_image,
|
| 192 |
+
num_inference_steps=num_steps,
|
| 193 |
+
guidance_scale=guidance_scale,
|
| 194 |
+
eta=eta,
|
| 195 |
+
controlnet_conditioning_scale=controlnet_scale,
|
| 196 |
+
generator=generator,
|
| 197 |
+
).images[0]
|
| 198 |
+
|
| 199 |
+
# Create a grid of the depth map and result
|
| 200 |
+
grid = make_image_grid([depth_image, image], rows=1, cols=2)
|
| 201 |
+
return grid, "Image generated successfully!"
|
| 202 |
+
except Exception as e:
|
| 203 |
+
return None, f"Error generating image: {str(e)}"
|
| 204 |
|
| 205 |
def inpaint_image(prompt, init_image, mask_image, seed, num_steps, guidance_scale, eta, strength):
|
| 206 |
+
try:
|
| 207 |
+
# Initialize the pipeline
|
| 208 |
+
base_model_id = "diffusers/stable-diffusion-xl-1.0-inpainting-0.1"
|
| 209 |
+
tcd_lora_id = "h1t/TCD-SDXL-LoRA"
|
| 210 |
+
|
| 211 |
+
# Use CPU for inference
|
| 212 |
+
pipe = AutoPipelineForInpainting.from_pretrained(
|
| 213 |
+
base_model_id,
|
| 214 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
| 215 |
+
)
|
| 216 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 217 |
+
|
| 218 |
+
# Load and fuse LoRA weights
|
| 219 |
+
pipe.load_lora_weights(tcd_lora_id)
|
| 220 |
+
pipe.fuse_lora()
|
| 221 |
+
|
| 222 |
+
# Generate the image
|
| 223 |
+
generator = torch.Generator().manual_seed(seed)
|
| 224 |
+
image = pipe(
|
| 225 |
+
prompt=prompt,
|
| 226 |
+
image=init_image,
|
| 227 |
+
mask_image=mask_image,
|
| 228 |
+
num_inference_steps=num_steps,
|
| 229 |
+
guidance_scale=guidance_scale,
|
| 230 |
+
eta=eta,
|
| 231 |
+
strength=strength,
|
| 232 |
+
generator=generator,
|
| 233 |
+
).images[0]
|
| 234 |
+
|
| 235 |
+
# Create a grid of the original image, mask, and result
|
| 236 |
+
grid = make_image_grid([init_image, mask_image, image], rows=1, cols=3)
|
| 237 |
+
return grid, "Image generated successfully!"
|
| 238 |
+
except Exception as e:
|
| 239 |
+
return None, f"Error generating image: {str(e)}"
|
| 240 |
|
| 241 |
def generate_animation(prompt, seed, num_steps, guidance_scale, eta, num_frames, motion_scale):
|
| 242 |
+
try:
|
| 243 |
+
# Initialize the pipeline
|
| 244 |
+
base_model_id = "frankjoshua/toonyou_beta6"
|
| 245 |
+
motion_adapter_id = "guoyww/animatediff-motion-adapter-v1-5"
|
| 246 |
+
tcd_lora_id = "h1t/TCD-SD15-LoRA"
|
| 247 |
+
motion_lora_id = "guoyww/animatediff-motion-lora-zoom-in"
|
| 248 |
+
|
| 249 |
+
# Load motion adapter
|
| 250 |
+
adapter = MotionAdapter.from_pretrained(motion_adapter_id)
|
| 251 |
+
|
| 252 |
+
# Initialize pipeline with CPU optimization
|
| 253 |
+
pipe = AnimateDiffPipeline.from_pretrained(
|
| 254 |
+
base_model_id,
|
| 255 |
+
motion_adapter=adapter,
|
| 256 |
+
torch_dtype=torch.float32, # Use float32 for CPU
|
| 257 |
+
low_cpu_mem_usage=True, # Enable low CPU memory usage
|
| 258 |
+
use_safetensors=False # Use standard PyTorch weights
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
# Set TCD scheduler
|
| 262 |
+
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
| 263 |
+
|
| 264 |
+
# Load LoRA weights
|
| 265 |
+
pipe.load_lora_weights(tcd_lora_id, adapter_name="tcd")
|
| 266 |
+
pipe.load_lora_weights(
|
| 267 |
+
motion_lora_id,
|
| 268 |
+
adapter_name="motion-lora"
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
# Set adapter weights
|
| 272 |
+
pipe.set_adapters(["tcd", "motion-lora"], adapter_weights=[1.0, motion_scale])
|
| 273 |
+
|
| 274 |
+
# Generate animation
|
| 275 |
+
generator = torch.Generator().manual_seed(seed)
|
| 276 |
+
frames = pipe(
|
| 277 |
+
prompt=prompt,
|
| 278 |
+
num_inference_steps=num_steps,
|
| 279 |
+
guidance_scale=guidance_scale,
|
| 280 |
+
cross_attention_kwargs={"scale": 1},
|
| 281 |
+
num_frames=num_frames,
|
| 282 |
+
eta=eta,
|
| 283 |
+
generator=generator
|
| 284 |
+
).frames[0]
|
| 285 |
+
|
| 286 |
+
# Export to GIF
|
| 287 |
+
gif_path = "animation.gif"
|
| 288 |
+
export_to_gif(frames, gif_path)
|
| 289 |
+
return gif_path, "Animation generated successfully!"
|
| 290 |
+
except Exception as e:
|
| 291 |
+
return None, f"Error generating animation: {str(e)}"
|
| 292 |
|
| 293 |
# Create the Gradio interface
|
| 294 |
with gr.Blocks(title="TCD-SDXL Image Generator") as demo:
|
|
|
|
| 309 |
text_guidance = gr.Slider(minimum=0, maximum=1, value=0, label="Guidance Scale")
|
| 310 |
text_eta = gr.Slider(minimum=0, maximum=1, value=0.3, label="Eta")
|
| 311 |
text_button = gr.Button("Generate")
|
| 312 |
+
text_status = gr.Textbox(label="Status", interactive=False)
|
| 313 |
with gr.Column():
|
| 314 |
text_output = gr.Image(label="Generated Image")
|
| 315 |
|
| 316 |
text_button.click(
|
| 317 |
fn=generate_image,
|
| 318 |
inputs=[text_prompt, text_seed, text_steps, text_guidance, text_eta],
|
| 319 |
+
outputs=[text_output, text_status],
|
| 320 |
+
api_name="generate_image"
|
| 321 |
)
|
| 322 |
|
| 323 |
with gr.TabItem("Inpainting"):
|
|
|
|
| 338 |
inpaint_button = gr.Button("Inpaint")
|
| 339 |
with gr.Column():
|
| 340 |
inpaint_output = gr.Image(label="Result (Original | Mask | Generated)")
|
| 341 |
+
inpaint_status = gr.Textbox(label="Status", interactive=False)
|
| 342 |
|
| 343 |
inpaint_button.click(
|
| 344 |
fn=inpaint_image,
|
|
|
|
| 346 |
inpaint_prompt, init_image, mask_image, inpaint_seed,
|
| 347 |
inpaint_steps, inpaint_guidance, inpaint_eta, inpaint_strength
|
| 348 |
],
|
| 349 |
+
outputs=[inpaint_output, inpaint_status]
|
| 350 |
)
|
| 351 |
|
| 352 |
with gr.TabItem("Community Models"):
|
|
|
|
| 369 |
community_button = gr.Button("Generate")
|
| 370 |
with gr.Column():
|
| 371 |
community_output = gr.Image(label="Generated Image")
|
| 372 |
+
community_status = gr.Textbox(label="Status", interactive=False)
|
| 373 |
|
| 374 |
community_button.click(
|
| 375 |
fn=generate_community_image,
|
|
|
|
| 377 |
community_prompt, model_dropdown, community_seed,
|
| 378 |
community_steps, community_guidance, community_eta
|
| 379 |
],
|
| 380 |
+
outputs=[community_output, community_status]
|
| 381 |
)
|
| 382 |
|
| 383 |
with gr.TabItem("Style Mixing"):
|
|
|
|
| 396 |
style_button = gr.Button("Generate")
|
| 397 |
with gr.Column():
|
| 398 |
style_output = gr.Image(label="Generated Image")
|
| 399 |
+
style_status = gr.Textbox(label="Status", interactive=False)
|
| 400 |
|
| 401 |
style_button.click(
|
| 402 |
fn=generate_style_mix,
|
|
|
|
| 404 |
style_prompt, style_seed, style_steps,
|
| 405 |
style_guidance, style_eta, style_weight
|
| 406 |
],
|
| 407 |
+
outputs=[style_output, style_status]
|
| 408 |
)
|
| 409 |
|
| 410 |
with gr.TabItem("ControlNet"):
|
|
|
|
| 424 |
control_button = gr.Button("Generate")
|
| 425 |
with gr.Column():
|
| 426 |
control_output = gr.Image(label="Result (Depth Map | Generated)")
|
| 427 |
+
control_status = gr.Textbox(label="Status", interactive=False)
|
| 428 |
|
| 429 |
control_button.click(
|
| 430 |
fn=generate_controlnet,
|
|
|
|
| 432 |
control_prompt, control_image, control_seed,
|
| 433 |
control_steps, control_guidance, control_eta, control_scale
|
| 434 |
],
|
| 435 |
+
outputs=[control_output, control_status]
|
| 436 |
)
|
| 437 |
|
| 438 |
with gr.TabItem("Animation"):
|
|
|
|
| 452 |
anim_button = gr.Button("Generate Animation")
|
| 453 |
with gr.Column():
|
| 454 |
anim_output = gr.Image(label="Generated Animation")
|
| 455 |
+
anim_status = gr.Textbox(label="Status", interactive=False)
|
| 456 |
|
| 457 |
anim_button.click(
|
| 458 |
fn=generate_animation,
|
|
|
|
| 461 |
anim_guidance, anim_eta, anim_frames,
|
| 462 |
anim_motion_scale
|
| 463 |
],
|
| 464 |
+
outputs=[anim_output, anim_status]
|
| 465 |
)
|
| 466 |
|
| 467 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -2,7 +2,7 @@ torch>=2.0.0
|
|
| 2 |
diffusers>=0.24.0
|
| 3 |
transformers>=4.36.0
|
| 4 |
accelerate>=0.25.0
|
| 5 |
-
gradio>=4.
|
| 6 |
safetensors>=0.4.0
|
| 7 |
peft>=0.7.0
|
| 8 |
requests>=2.31.0
|
|
|
|
| 2 |
diffusers>=0.24.0
|
| 3 |
transformers>=4.36.0
|
| 4 |
accelerate>=0.25.0
|
| 5 |
+
gradio>=4.19.2
|
| 6 |
safetensors>=0.4.0
|
| 7 |
peft>=0.7.0
|
| 8 |
requests>=2.31.0
|