multimodalart HF Staff commited on
Commit
109501b
·
verified ·
1 Parent(s): 3b081e5

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +74 -9
app.py CHANGED
@@ -15,8 +15,10 @@ import gradio as gr
15
  from PIL import Image
16
 
17
  from boogu.pipelines.boogu.pipeline_boogu import BooguImagePipeline
 
18
 
19
  MODEL_ID = "Boogu/Boogu-Image-0.1-Edit"
 
20
  AOTI_REPO = "multimodalart/Boogu-Image-0.1-Edit-aoti"
21
 
22
  pipe = BooguImagePipeline.from_pretrained(
@@ -26,8 +28,24 @@ pipe = BooguImagePipeline.from_pretrained(
26
  )
27
  pipe.to("cuda")
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Swap the 24 repeated single-stream blocks for their AoTI-compiled graph
30
  # (one shared compiled graph, per-block weights). Falls back to eager on any error.
 
31
  try:
32
  from pathlib import Path
33
  from huggingface_hub import snapshot_download
@@ -50,8 +68,9 @@ RESOLUTIONS = {
50
  }
51
 
52
 
53
- def _duration(image, instruction, resolution, num_inference_steps, *args, **kwargs):
54
- base = int(num_inference_steps) * 4 + 60
 
55
  return base * 2 if resolution == "2K" else base
56
 
57
 
@@ -59,6 +78,7 @@ def _duration(image, instruction, resolution, num_inference_steps, *args, **kwar
59
  def edit(
60
  image,
61
  instruction,
 
62
  resolution,
63
  num_inference_steps,
64
  text_guidance_scale,
@@ -77,7 +97,27 @@ def edit(
77
  res = RESOLUTIONS[resolution]
78
  generator = torch.Generator("cuda").manual_seed(seed)
79
 
80
- if image is None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Text-to-image: no reference image, output size is set explicitly.
82
  size = 1024 if resolution == "1K" else 2048
83
  result = pipe(
@@ -122,14 +162,18 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
122
  with gr.Column(elem_id="col-container"):
123
  gr.Markdown(
124
  """
125
- # 🍊 Boogu-Image-0.1-Edit
126
- Unified generation/editing with [Boogu-Image-0.1-Edit](https://huggingface.co/Boogu/Boogu-Image-0.1-Edit) —
127
- a 10B model (Qwen3-VL + FLUX VAE). Leave the image empty for text-to-image, or upload one to edit it
128
- (English or Chinese).
129
  """
130
  )
131
  with gr.Row():
132
  with gr.Column():
 
 
 
 
133
  image = gr.Image(
134
  label="Input image (leave empty for text-to-image)",
135
  type="filepath", height=360,
@@ -145,7 +189,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
145
  choices=["1K", "2K"], value="1K", label="Output resolution"
146
  )
147
  num_inference_steps = gr.Slider(
148
- minimum=10, maximum=50, step=1, value=40,
149
  label="Inference steps",
150
  )
151
  text_guidance_scale = gr.Slider(
@@ -174,8 +218,29 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
174
  inputs=[image, instruction],
175
  )
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  inputs = [
178
- image, instruction, resolution, num_inference_steps,
179
  text_guidance_scale, image_guidance_scale, seed, randomize_seed,
180
  ]
181
  run_button.click(fn=edit, inputs=inputs, outputs=[result, seed])
 
15
  from PIL import Image
16
 
17
  from boogu.pipelines.boogu.pipeline_boogu import BooguImagePipeline
18
+ from boogu.pipelines.boogu.pipeline_boogu_turbo import BooguImageTurboPipeline
19
 
20
  MODEL_ID = "Boogu/Boogu-Image-0.1-Edit"
21
+ TURBO_ID = "Boogu/Boogu-Image-0.1-Turbo"
22
  AOTI_REPO = "multimodalart/Boogu-Image-0.1-Edit-aoti"
23
 
24
  pipe = BooguImagePipeline.from_pretrained(
 
28
  )
29
  pipe.to("cuda")
30
 
31
+ # Turbo shares the (byte-identical) mllm / vae / processor / scheduler with Edit;
32
+ # only the transformer differs. Load just the Turbo transformer and build a Turbo
33
+ # pipeline reusing the already-resident components — no duplicate 17.5GB mllm.
34
+ turbo_transformer = type(pipe.transformer).from_pretrained(
35
+ TURBO_ID,
36
+ subfolder="transformer",
37
+ torch_dtype=torch.bfloat16,
38
+ )
39
+ _turbo_components = dict(pipe.components)
40
+ _turbo_components["transformer"] = turbo_transformer
41
+ turbo_pipe = BooguImageTurboPipeline(**_turbo_components)
42
+ turbo_pipe.text_instruction_rewriter = pipe.text_instruction_rewriter
43
+ turbo_pipe.instruction_rewriter_processor = pipe.instruction_rewriter_processor
44
+ turbo_pipe.to("cuda")
45
+
46
  # Swap the 24 repeated single-stream blocks for their AoTI-compiled graph
47
  # (one shared compiled graph, per-block weights). Falls back to eager on any error.
48
+ # Only the Edit transformer is compiled for now; Turbo runs eager (baseline).
49
  try:
50
  from pathlib import Path
51
  from huggingface_hub import snapshot_download
 
68
  }
69
 
70
 
71
+ def _duration(image, instruction, model_choice, resolution, num_inference_steps, *args, **kwargs):
72
+ per_step = 4 if model_choice == "Turbo" else 4
73
+ base = int(num_inference_steps) * per_step + (40 if model_choice == "Turbo" else 60)
74
  return base * 2 if resolution == "2K" else base
75
 
76
 
 
78
  def edit(
79
  image,
80
  instruction,
81
+ model_choice,
82
  resolution,
83
  num_inference_steps,
84
  text_guidance_scale,
 
97
  res = RESOLUTIONS[resolution]
98
  generator = torch.Generator("cuda").manual_seed(seed)
99
 
100
+ if model_choice == "Turbo":
101
+ # DMD few-step text-to-image: no reference image, no CFG (all scales == 1.0).
102
+ size = 1024 if resolution == "1K" else 2048
103
+ result = turbo_pipe(
104
+ instruction=[instruction.strip()],
105
+ negative_instruction="",
106
+ empty_instruction="",
107
+ height=size,
108
+ width=size,
109
+ max_input_image_pixels=res["pixels"],
110
+ max_input_image_side_length=res["side"],
111
+ num_inference_steps=int(num_inference_steps),
112
+ text_guidance_scale=1.0,
113
+ image_guidance_scale=1.0,
114
+ empty_instruction_guidance_scale=0.0,
115
+ use_dmd_student_inference=True,
116
+ dmd_conditioning_sigma=0.001,
117
+ generator=generator,
118
+ device="cuda",
119
+ ).images[0]
120
+ elif image is None:
121
  # Text-to-image: no reference image, output size is set explicitly.
122
  size = 1024 if resolution == "1K" else 2048
123
  result = pipe(
 
162
  with gr.Column(elem_id="col-container"):
163
  gr.Markdown(
164
  """
165
+ # 🍊 Boogu-Image-0.1
166
+ Unified generation/editing with [Boogu-Image-0.1](https://huggingface.co/Boogu) — a 10B model
167
+ (Qwen3-VL + FLUX VAE). **Edit** does text-to-image and instruction editing (English or Chinese);
168
+ **Turbo** is a 4-step distilled text-to-image model.
169
  """
170
  )
171
  with gr.Row():
172
  with gr.Column():
173
+ model_choice = gr.Radio(
174
+ choices=["Edit", "Turbo"], value="Edit", label="Model",
175
+ info="Edit: T2I + image editing (~40 steps). Turbo: fast 4-step T2I (no image input).",
176
+ )
177
  image = gr.Image(
178
  label="Input image (leave empty for text-to-image)",
179
  type="filepath", height=360,
 
189
  choices=["1K", "2K"], value="1K", label="Output resolution"
190
  )
191
  num_inference_steps = gr.Slider(
192
+ minimum=1, maximum=50, step=1, value=40,
193
  label="Inference steps",
194
  )
195
  text_guidance_scale = gr.Slider(
 
218
  inputs=[image, instruction],
219
  )
220
 
221
+ def _on_model_change(choice):
222
+ if choice == "Turbo":
223
+ return (
224
+ gr.update(visible=False), # image (Turbo is T2I only)
225
+ gr.update(value=4, minimum=1, maximum=8, label="Inference steps (Turbo)"),
226
+ gr.update(value=1.0, interactive=False), # text guidance (CFG off for DMD)
227
+ gr.update(value=1.0, interactive=False), # image guidance (unused)
228
+ )
229
+ return (
230
+ gr.update(visible=True),
231
+ gr.update(value=40, minimum=1, maximum=50, label="Inference steps"),
232
+ gr.update(value=4.0, interactive=True),
233
+ gr.update(value=1.0, interactive=True),
234
+ )
235
+
236
+ model_choice.change(
237
+ _on_model_change,
238
+ inputs=[model_choice],
239
+ outputs=[image, num_inference_steps, text_guidance_scale, image_guidance_scale],
240
+ )
241
+
242
  inputs = [
243
+ image, instruction, model_choice, resolution, num_inference_steps,
244
  text_guidance_scale, image_guidance_scale, seed, randomize_seed,
245
  ]
246
  run_button.click(fn=edit, inputs=inputs, outputs=[result, seed])