GroundBi / app.py
naonauno's picture
Update app.py
a23bb4f verified
raw
history blame
1.41 kB
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()