Commit
·
0ec1b6c
1
Parent(s):
a685f13
Refactor flux_helpers.py to update pipeline mode based on request type
Browse filesRefactor flux_helpers.py to add cleanup in finally block
Refactor image_tab.py to update custom Lora selection order
Refactor flux_events.py to add GPU duration for image generation
Refactor flux_helpers.py to use CUDA device for generator seed
- modules/events/flux_events.py +75 -72
- modules/helpers/flux_helpers.py +1 -0
modules/events/flux_events.py
CHANGED
@@ -217,82 +217,85 @@ def generate_image(
|
|
217 |
image_num_inference_steps, image_guidance_scale, image_seed,
|
218 |
refiner, vae
|
219 |
):
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
if len(enabled_loras) > 0:
|
240 |
-
base_args.loras = []
|
241 |
-
for enabled_lora, slider in zip(enabled_loras, [lora_slider_0, lora_slider_1, lora_slider_2, lora_slider_3, lora_slider_4, lora_slider_5]):
|
242 |
-
if enabled_lora['repo_id']:
|
243 |
-
base_args.loras.append({
|
244 |
-
"repo_id": enabled_lora['repo_id'],
|
245 |
-
"weight": slider
|
246 |
-
})
|
247 |
-
|
248 |
-
image = None
|
249 |
-
mask_image = None
|
250 |
-
strength = None
|
251 |
-
|
252 |
-
if img2img_image:
|
253 |
-
image = img2img_image
|
254 |
-
strength = float(img2img_strength)
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
265 |
|
266 |
-
if
|
267 |
-
|
|
|
|
|
|
|
268 |
**base_args.__dict__,
|
269 |
image=image,
|
270 |
-
mask_image=mask_image,
|
271 |
strength=strength
|
272 |
)
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
280 |
-
|
281 |
-
base_args
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
base_args.controlnet_config.control_images.append(pose_image)
|
287 |
-
base_args.controlnet_config.controlnet_conditioning_scale.append(float(pose_strength))
|
288 |
-
if depth_image:
|
289 |
-
base_args.controlnet_config.controlnets.append("depth")
|
290 |
-
base_args.controlnet_config.control_images.append(depth_image)
|
291 |
-
base_args.controlnet_config.controlnet_conditioning_scale.append(float(depth_strength))
|
292 |
-
else:
|
293 |
-
base_args = BaseReq(**base_args.__dict__)
|
294 |
-
|
295 |
-
return gr.update(
|
296 |
-
value=gen_img(base_args),
|
297 |
-
interactive=True
|
298 |
-
)
|
|
|
217 |
image_num_inference_steps, image_guidance_scale, image_seed,
|
218 |
refiner, vae
|
219 |
):
|
220 |
+
try:
|
221 |
+
base_args = {
|
222 |
+
"model": model,
|
223 |
+
"prompt": prompt,
|
224 |
+
"fast_generation": fast_generation,
|
225 |
+
"loras": None,
|
226 |
+
"resize_mode": resize_mode,
|
227 |
+
"scheduler": scheduler,
|
228 |
+
"height": int(image_height),
|
229 |
+
"width": int(image_width),
|
230 |
+
"num_images_per_prompt": float(image_num_images_per_prompt),
|
231 |
+
"num_inference_steps": float(image_num_inference_steps),
|
232 |
+
"guidance_scale": float(image_guidance_scale),
|
233 |
+
"seed": int(image_seed),
|
234 |
+
"refiner": refiner,
|
235 |
+
"vae": vae,
|
236 |
+
"controlnet_config": None,
|
237 |
+
}
|
238 |
+
base_args = BaseReq(**base_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
+
if len(enabled_loras) > 0:
|
241 |
+
base_args.loras = []
|
242 |
+
for enabled_lora, slider in zip(enabled_loras, [lora_slider_0, lora_slider_1, lora_slider_2, lora_slider_3, lora_slider_4, lora_slider_5]):
|
243 |
+
if enabled_lora['repo_id']:
|
244 |
+
base_args.loras.append({
|
245 |
+
"repo_id": enabled_lora['repo_id'],
|
246 |
+
"weight": slider
|
247 |
+
})
|
248 |
+
|
249 |
+
image = None
|
250 |
+
mask_image = None
|
251 |
+
strength = None
|
252 |
|
253 |
+
if img2img_image:
|
254 |
+
image = img2img_image
|
255 |
+
strength = float(img2img_strength)
|
256 |
+
|
257 |
+
base_args = BaseImg2ImgReq(
|
258 |
**base_args.__dict__,
|
259 |
image=image,
|
|
|
260 |
strength=strength
|
261 |
)
|
262 |
+
elif inpaint_image:
|
263 |
+
image = inpaint_image['background'] if not all(pixel == (0, 0, 0) for pixel in list(inpaint_image['background'].getdata())) else None
|
264 |
+
mask_image = inpaint_image['layers'][0] if image else None
|
265 |
+
strength = float(inpaint_strength)
|
266 |
+
|
267 |
+
if image and mask_image:
|
268 |
+
base_args = BaseInpaintReq(
|
269 |
+
**base_args.__dict__,
|
270 |
+
image=image,
|
271 |
+
mask_image=mask_image,
|
272 |
+
strength=strength
|
273 |
+
)
|
274 |
+
elif any([canny_image, pose_image, depth_image]):
|
275 |
+
base_args.controlnet_config = ControlNetReq(
|
276 |
+
controlnets=[],
|
277 |
+
control_images=[],
|
278 |
+
controlnet_conditioning_scale=[]
|
279 |
+
)
|
280 |
+
|
281 |
+
if canny_image:
|
282 |
+
base_args.controlnet_config.controlnets.append("canny")
|
283 |
+
base_args.controlnet_config.control_images.append(canny_image)
|
284 |
+
base_args.controlnet_config.controlnet_conditioning_scale.append(float(canny_strength))
|
285 |
+
if pose_image:
|
286 |
+
base_args.controlnet_config.controlnets.append("pose")
|
287 |
+
base_args.controlnet_config.control_images.append(pose_image)
|
288 |
+
base_args.controlnet_config.controlnet_conditioning_scale.append(float(pose_strength))
|
289 |
+
if depth_image:
|
290 |
+
base_args.controlnet_config.controlnets.append("depth")
|
291 |
+
base_args.controlnet_config.control_images.append(depth_image)
|
292 |
+
base_args.controlnet_config.controlnet_conditioning_scale.append(float(depth_strength))
|
293 |
+
else:
|
294 |
+
base_args = BaseReq(**base_args.__dict__)
|
295 |
|
296 |
+
return gr.update(
|
297 |
+
value=gen_img(base_args),
|
298 |
+
interactive=True
|
299 |
+
)
|
300 |
+
except Exception as e:
|
301 |
+
raise gr.Error(f"Error: {e}") from e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/helpers/flux_helpers.py
CHANGED
@@ -113,6 +113,7 @@ def gen_img(request: BaseReq | BaseImg2ImgReq | BaseInpaintReq):
|
|
113 |
args['mask_image'] = resize_images([request.mask_image], request.height, request.width, request.resize_mode)[0]
|
114 |
|
115 |
# Generate
|
|
|
116 |
images = pipeline(**args).images
|
117 |
|
118 |
# Refiner
|
|
|
113 |
args['mask_image'] = resize_images([request.mask_image], request.height, request.width, request.resize_mode)[0]
|
114 |
|
115 |
# Generate
|
116 |
+
gr.Info(f"Using {pipeline}", duration=150)
|
117 |
images = pipeline(**args).images
|
118 |
|
119 |
# Refiner
|