MCPcopy Create free account
hub / github.com/modelscope/DiffSynth-Studio / generate_image

Function generate_image

apps/gradio/entity_level_control.py:281–324  ·  view source on GitHub ↗
(model_type, model_path, prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width, return_with_mask, seed, input_image, background_weight, random_mask_dir, *args, progress=gr.Progress())

Source from the content-addressed store, hash-verified

279 triggers=run_button.click
280 )
281 def generate_image(model_type, model_path, prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width, return_with_mask, seed, input_image, background_weight, random_mask_dir, *args, progress=gr.Progress()):
282 _, pipe = load_model(model_type, model_path)
283 input_params = {
284 "prompt": prompt,
285 "negative_prompt": negative_prompt,
286 "cfg_scale": cfg_scale,
287 "num_inference_steps": num_inference_steps,
288 "height": height,
289 "width": width,
290 "progress_bar_cmd": progress.tqdm,
291 }
292 if isinstance(pipe, FluxImagePipeline):
293 input_params["embedded_guidance"] = embedded_guidance
294 if input_image is not None:
295 input_params["input_image"] = input_image.resize((width, height)).convert("RGB")
296 input_params["enable_eligen_inpaint"] = True
297
298 local_prompt_list, canvas_list = (
299 args[0 * config["max_num_painter_layers"]: 1 * config["max_num_painter_layers"]],
300 args[1 * config["max_num_painter_layers"]: 2 * config["max_num_painter_layers"]],
301 )
302 local_prompts, masks = [], []
303 for local_prompt, canvas in zip(local_prompt_list, canvas_list):
304 if isinstance(local_prompt, str) and len(local_prompt) > 0:
305 local_prompts.append(local_prompt)
306 masks.append(Image.fromarray(canvas["layers"][0][:, :, -1]).convert("RGB"))
307 entity_masks = None if len(masks) == 0 else masks
308 entity_prompts = None if len(local_prompts) == 0 else local_prompts
309 input_params.update({
310 "eligen_entity_prompts": entity_prompts,
311 "eligen_entity_masks": entity_masks,
312 })
313 torch.manual_seed(seed)
314 # save_mask_prompts(masks, local_prompts, prompt, seed, random_mask_dir)
315 image = pipe(**input_params)
316 masks = [mask.resize(image.size) for mask in masks]
317 image_with_mask = visualize_masks(image, masks, local_prompts)
318
319 real_output = gr.State(image)
320 mask_out = gr.State(image_with_mask)
321
322 if return_with_mask:
323 return image_with_mask, real_output, mask_out
324 return image, real_output, mask_out
325
326 @gr.on(inputs=[input_image] + canvas_list, outputs=canvas_list, triggers=send_input_to_painter.click)
327 def send_input_to_painter_background(input_image, *canvas_list):

Callers

nothing calls this directly

Calls 3

load_modelFunction · 0.70
visualize_masksFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected