Spaces:
Runtime error
Runtime error
File size: 1,463 Bytes
a0ff319 666ddb4 97baa3c a0ff319 666ddb4 a0ff319 10b626b a0ff319 97baa3c a0ff319 42cdd34 666ddb4 10b626b 42cdd34 666ddb4 97baa3c 041beae 97baa3c 041beae f5b6e2c 041beae 97baa3c 041beae 97baa3c 041beae 97baa3c 041beae |
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 |
from diffusers import DiffusionPipeline, LCMScheduler
from diffusers.models.modeling_outputs import Transformer2DModelOutput
from optimum.intel import OVStableDiffusionXLPipeline
import gradio as gr
# Loading the model
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
pipe = DiffusionPipeline.from_pretrained(model_id)
# Setting the scheduler
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# Loading LoRA weights
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
# Converting the model to OpenVINO format
pipeline = OVStableDiffusionXLPipeline.from_pretrained(
model_id,
export=True,
framework="pt"
)
def generate_images(prompt, batch_size, num_inference_steps, guidance_scale):
images = []
for _ in range(batch_size):
results = pipeline(
prompt=prompt,
num_inference_steps=num_inference_steps,
guidance_scale=guidance_scale
)
images.append(results.images[0])
return images
iface = gr.Interface(
fn=generate_images,
inputs=[
gr.Textbox(label="Prompt"),
gr.Slider(label="Batch Size", minimum=1, maximum=12, step=1, value=1),
gr.Slider(label="Num Inference Steps", minimum=1, maximum=6, step=1, value=4),
gr.Slider(label="Guidance Scale", minimum=0.0, maximum=3, step=0.1, value=1.4)
],
outputs=gr.Gallery(label="Generated Images"),
title="Fast SDXL Generation on CPU"
)
iface.launch() |