OPENVINO / app.py
tejani's picture
Update app.py
bdbccd8 verified
raw
history blame contribute delete
1.07 kB
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()