Spaces:
Runtime error
Runtime error
Add gradio ui
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
from diffusers.utils import load_image
|
5 |
+
from diffusers.pipelines.flux.pipeline_flux_controlnet import FluxControlNetPipeline
|
6 |
+
from diffusers.models.controlnet_flux import FluxControlNetModel
|
7 |
+
|
8 |
+
base_model = 'black-forest-labs/FLUX.1-dev'
|
9 |
+
controlnet_model = 'promeai/FLUX.1-controlnet-lineart-promeai'
|
10 |
+
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
|
11 |
+
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
12 |
+
pipe.to("cuda")
|
13 |
+
|
14 |
+
def generate_image(prompt, control_image, controlnet_conditioning_scale, num_inference_steps, guidance_scale):
|
15 |
+
control_image = load_image(control_image) if isinstance(control_image, str) else control_image
|
16 |
+
|
17 |
+
result = pipe(
|
18 |
+
prompt,
|
19 |
+
control_image=control_image,
|
20 |
+
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
21 |
+
num_inference_steps=num_inference_steps,
|
22 |
+
guidance_scale=guidance_scale,
|
23 |
+
).images[0]
|
24 |
+
|
25 |
+
return result
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("# FLUX ControlNet Pipeline Interface")
|
29 |
+
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Enter your prompt here...")
|
33 |
+
control_image = gr.Image(source="upload", type="filepath", label="Control Image")
|
34 |
+
|
35 |
+
controlnet_conditioning_scale = gr.Slider(0.0, 1.0, value=0.6, label="ControlNet Conditioning Scale")
|
36 |
+
num_inference_steps = gr.Slider(1, 100, value=28, step=1, label="Number of Inference Steps")
|
37 |
+
guidance_scale = gr.Slider(1.0, 10.0, value=3.5, label="Guidance Scale")
|
38 |
+
|
39 |
+
generate_button = gr.Button("Generate Image")
|
40 |
+
|
41 |
+
with gr.Column():
|
42 |
+
output_image = gr.Image(label="Generated Image")
|
43 |
+
generate_button.click(
|
44 |
+
generate_image,
|
45 |
+
inputs=[prompt, control_image, controlnet_conditioning_scale, num_inference_steps, guidance_scale],
|
46 |
+
outputs=output_image
|
47 |
+
)
|
48 |
+
|
49 |
+
demo.launch()
|