File size: 1,406 Bytes
e29a7a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline, ControlNetModel
from safetensors.torch import load_file

# Initialize the pipeline with CPU
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(
    model_id,
    torch_dtype=torch.float32,
)

# Load your ControlNet LoRA
lora_path = "naonauno/40k-half-sd15"
pipe.load_lora_weights(lora_path)

def generate_image(prompt, negative_prompt, guidance_scale, steps):
    with torch.no_grad():
        image = pipe(
            prompt=prompt,
            negative_prompt=negative_prompt,
            num_inference_steps=steps,
            guidance_scale=guidance_scale,
        ).images[0]
    return image

# Create the Gradio interface
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(label="Prompt")
            negative_prompt = gr.Textbox(label="Negative Prompt")
            guidance_scale = gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale")
            steps = gr.Slider(minimum=1, maximum=100, value=50, label="Steps")
            generate = gr.Button("Generate")
        
        with gr.Column():
            result = gr.Image(label="Generated Image")
    
    generate.click(
        fn=generate_image,
        inputs=[prompt, negative_prompt, guidance_scale, steps],
        outputs=result
    )

demo.launch()