File size: 1,068 Bytes
3daf324
7586093
3daf324
 
7586093
3daf324
7586093
 
bdbccd8
7586093
 
 
 
 
3daf324
 
 
de62ac6
3daf324
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch

# Load the model
model_id = "Intel/sd-1.5-square-quantized"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)

# Optional: Try OpenVINO if available
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).")

# Define the inference function
def generate_image(prompt):
    image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
    return image

# Create the Gradio interface
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."
)

# Launch the interface
interface.launch()