import gradio as gr import torch from PIL import Image from diffusers.utils import load_image from diffusers.pipelines.flux.pipeline_flux_controlnet import FluxControlNetPipeline from diffusers.models.controlnet_flux import FluxControlNetModel base_model = 'black-forest-labs/FLUX.1-dev' controlnet_model = 'promeai/FLUX.1-controlnet-lineart-promeai' controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16) pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16) pipe.to("cuda") def generate_image(prompt, control_image, controlnet_conditioning_scale, num_inference_steps, guidance_scale): control_image = load_image(control_image) if isinstance(control_image, str) else control_image result = pipe( prompt, control_image=control_image, controlnet_conditioning_scale=controlnet_conditioning_scale, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, ).images[0] return result with gr.Blocks() as demo: gr.Markdown("# FLUX ControlNet Pipeline Interface") with gr.Row(): with gr.Column(): prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Enter your prompt here...") control_image = gr.Image(source="upload", type="filepath", label="Control Image") controlnet_conditioning_scale = gr.Slider(0.0, 1.0, value=0.6, label="ControlNet Conditioning Scale") num_inference_steps = gr.Slider(1, 100, value=28, step=1, label="Number of Inference Steps") guidance_scale = gr.Slider(1.0, 10.0, value=3.5, label="Guidance Scale") generate_button = gr.Button("Generate Image") with gr.Column(): output_image = gr.Image(label="Generated Image") generate_button.click( generate_image, inputs=[prompt, control_image, controlnet_conditioning_scale, num_inference_steps, guidance_scale], outputs=output_image ) demo.launch()