Mccscs2 commited on
Commit
fff1b72
·
verified ·
1 Parent(s): a41840b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,7 +1,12 @@
1
  import torch
2
  import spaces
3
  import gradio as gr
4
- from diffusers import DiffusionPipeline, FluxImg2ImgPipeline, StableDiffusionInstructPix2PixPipeline
 
 
 
 
 
5
  from PIL import Image
6
 
7
  print("Loading pipelines...")
@@ -29,6 +34,15 @@ pipe_ip2p = StableDiffusionInstructPix2PixPipeline.from_pretrained(
29
  )
30
  pipe_ip2p.to("cuda")
31
 
 
 
 
 
 
 
 
 
 
32
  print("Pipelines loaded!")
33
 
34
  def resize_image(image, max_size=1024):
@@ -87,6 +101,15 @@ def generate_i2i(model_choice, input_image, prompt, strength, num_inference_step
87
  generator=generator,
88
  ).images[0]
89
 
 
 
 
 
 
 
 
 
 
90
  return image, seed
91
 
92
  examples_t2i = [
@@ -162,10 +185,11 @@ with gr.Blocks(fill_height=True) as demo:
162
  choices=[
163
  "FLUX.1-schnell (Creative, high change)",
164
  "InstructPix2Pix (Precise, preserves identity)",
 
165
  ],
166
  value="InstructPix2Pix (Precise, preserves identity)",
167
  label="🤖 Model",
168
- info="InstructPix2Pix is better for targeted edits like changing colours or styles while keeping the person. FLUX is better for creative transformations."
169
  )
170
 
171
  i2i_input = gr.Image(label="Upload Image", type="pil")
@@ -177,7 +201,7 @@ with gr.Blocks(fill_height=True) as demo:
177
 
178
  with gr.Accordion("⚙️ Advanced Settings", open=False):
179
  i2i_strength = gr.Slider(0.1, 1.0, value=0.75, step=0.05,
180
- label="Strength (FLUX only)",
181
  info="Higher = more change. Not used by InstructPix2Pix.")
182
  i2i_steps = gr.Slider(1, 50, value=20, step=1, label="Inference Steps")
183
  with gr.Row():
@@ -205,7 +229,7 @@ with gr.Blocks(fill_height=True) as demo:
205
  ---
206
  <div style="text-align: center; opacity: 0.7; font-size: 0.9em;">
207
  <strong>T2I:</strong> Tongyi-MAI/Z-Image-Turbo •
208
- <strong>I2I:</strong> FLUX.1-schnell + InstructPix2Pix
209
  </div>
210
  """
211
  )
 
1
  import torch
2
  import spaces
3
  import gradio as gr
4
+ from diffusers import (
5
+ DiffusionPipeline,
6
+ FluxImg2ImgPipeline,
7
+ StableDiffusionInstructPix2PixPipeline,
8
+ StableDiffusionXLImg2ImgPipeline,
9
+ )
10
  from PIL import Image
11
 
12
  print("Loading pipelines...")
 
34
  )
35
  pipe_ip2p.to("cuda")
36
 
37
+ # Image to image - SDXL
38
+ pipe_sdxl = StableDiffusionXLImg2ImgPipeline.from_pretrained(
39
+ "stabilityai/stable-diffusion-xl-base-1.0",
40
+ torch_dtype=torch.float16,
41
+ variant="fp16",
42
+ use_safetensors=True,
43
+ )
44
+ pipe_sdxl.to("cuda")
45
+
46
  print("Pipelines loaded!")
47
 
48
  def resize_image(image, max_size=1024):
 
101
  generator=generator,
102
  ).images[0]
103
 
104
+ elif model_choice == "SDXL (Balanced quality & control)":
105
+ image = pipe_sdxl(
106
+ prompt=prompt,
107
+ image=input_image,
108
+ strength=float(strength),
109
+ num_inference_steps=int(num_inference_steps),
110
+ generator=generator,
111
+ ).images[0]
112
+
113
  return image, seed
114
 
115
  examples_t2i = [
 
185
  choices=[
186
  "FLUX.1-schnell (Creative, high change)",
187
  "InstructPix2Pix (Precise, preserves identity)",
188
+ "SDXL (Balanced quality & control)",
189
  ],
190
  value="InstructPix2Pix (Precise, preserves identity)",
191
  label="🤖 Model",
192
+ info="InstructPix2Pix: best for targeted edits like colours/styles. SDXL: balanced quality and control. FLUX: creative transformations."
193
  )
194
 
195
  i2i_input = gr.Image(label="Upload Image", type="pil")
 
201
 
202
  with gr.Accordion("⚙️ Advanced Settings", open=False):
203
  i2i_strength = gr.Slider(0.1, 1.0, value=0.75, step=0.05,
204
+ label="Strength (FLUX & SDXL only)",
205
  info="Higher = more change. Not used by InstructPix2Pix.")
206
  i2i_steps = gr.Slider(1, 50, value=20, step=1, label="Inference Steps")
207
  with gr.Row():
 
229
  ---
230
  <div style="text-align: center; opacity: 0.7; font-size: 0.9em;">
231
  <strong>T2I:</strong> Tongyi-MAI/Z-Image-Turbo •
232
+ <strong>I2I:</strong> FLUX.1-schnell + InstructPix2Pix + SDXL
233
  </div>
234
  """
235
  )