|
import gradio as gr |
|
from diffusers import StableDiffusionPipeline |
|
import torch |
|
|
|
|
|
model_id = "Intel/sd-1.5-square-quantized" |
|
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) |
|
|
|
|
|
try: |
|
from optimum.intel import OVStableDiffusionPipeline |
|
pipe = OVStableDiffusionPipeline.from_pretrained(model_id, export=False, library_name="diffusers") |
|
except (ImportError, ModuleNotFoundError): |
|
print("Falling back to standard diffusers pipeline (no OpenVINO optimization).") |
|
|
|
|
|
def generate_image(prompt): |
|
image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0] |
|
return image |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_image, |
|
inputs=gr.Textbox(label="Enter your prompt"), |
|
outputs=gr.Image(label="Generated Image"), |
|
title="Stable Diffusion 1.5 Square Quantized Demo", |
|
description="Generate square images using Intel's quantized SD 1.5 model." |
|
) |
|
|
|
|
|
interface.launch() |