import gradio as gr from optimum.intel import OVStableDiffusionPipeline model_id = "yujiepan/dreamshaper-8-lcm-openvino-w8a8" pipeline = OVStableDiffusionPipeline.from_pretrained(model_id, device='CPU') def infer(prompt, num_inference_steps): image = pipeline( prompt=prompt, guidance_scale=1.0, num_inference_steps=num_inference_steps, width=512, height=512, num_images_per_prompt=1, ).images[0] return image examples = [ "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", "An astronaut riding a green horse", "A delicious ceviche cheesecake slice", ] css = """ #col-container { margin: 0 auto; max-width: 520px; } """ with gr.Blocks(css=css) as demo: with gr.Column(elem_id="col-container"): gr.Markdown("# Demo : yujiepan/dreamshaper-8-lcm-openvino-w8a8 ⚡") prompt = gr.Text( label="Prompt", show_label=False, placeholder="Enter your prompt", container=False, ) run_button = gr.Button("Run", scale=0) result = gr.Image(label="Result", show_label=False) with gr.Accordion("Advanced Settings", open=False): num_inference_steps = gr.Slider( label="Number of inference steps", minimum=1, maximum=50, step=1, value=8, ) gr.Examples( examples=examples, inputs=[prompt] ) run_button.click( fn=infer, inputs=[prompt, num_inference_steps], outputs=[result] ) demo.queue().launch(share=True)