GroundBi / app.py
naonauno's picture
Update app.py
d4a560e verified
raw
history blame
1.5 kB
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline
from huggingface_hub import hf_hub_download
# Initialize the pipeline with CPU
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float32,
)
# Load your LoRA weights
lora_path = "naonauno/40k-half-sd15"
pipe.load_lora_weights(
lora_path,
weight_name="40kHalf.safetensors"
)
# Set the cross attention processor scale
pipe.fuse_lora(scale=1.0)
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()