|
import gradio as gr |
|
from optimum.intel.openvino.modeling_diffusion import OVPipelineForText2Image |
|
import torch |
|
|
|
model_id = "AIFunOver/stable-diffusion-3.5-large-turbo-openvino-8bit" |
|
|
|
HIGH=1024 |
|
WIDTH=512 |
|
|
|
batch_size = -1 |
|
|
|
|
|
|
|
pipe = OVPipelineForText2Image.from_pretrained( |
|
model_id, |
|
compile = False, |
|
ov_config = {"CACHE_DIR":""}, |
|
torch_dtype=torch.uint8, |
|
safety_checker=None, |
|
use_safetensors=False, |
|
) |
|
print(pipe.scheduler.compatibles) |
|
|
|
|
|
pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1) |
|
|
|
pipe.compile() |
|
|
|
prompt="" |
|
negative_prompt=f"EasyNegative, cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly," |
|
|
|
def infer(prompt,negative_prompt): |
|
|
|
image = pipe( |
|
prompt = f",hyper-realistic 2K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic, ", |
|
negative_prompt = negative_prompt, |
|
width = WIDTH, |
|
height = HIGH, |
|
guidance_scale=1.0, |
|
num_inference_steps=6, |
|
num_images_per_prompt=1, |
|
).images[0] |
|
|
|
return image |
|
|
|
|
|
css=""" |
|
#col-container { |
|
margin: 0 auto; |
|
max-width: 520px; |
|
} |
|
""" |
|
|
|
|
|
power_device = "CPU" |
|
|
|
with gr.Blocks(css=css) as demo: |
|
|
|
with gr.Column(elem_id="col-container"): |
|
gr.Markdown(f""" |
|
# {model_id.split('/')[1]} {WIDTH}x{HIGH} |
|
Currently running on {power_device}. |
|
""") |
|
|
|
with gr.Row(): |
|
prompt = gr.Text( |
|
label="Prompt", |
|
show_label=False, |
|
max_lines=1, |
|
placeholder="Enter your prompt", |
|
container=False, |
|
) |
|
run_button = gr.Button("Run", scale=0) |
|
|
|
result = gr.Image(label="Result", show_label=False) |
|
|
|
run_button.click( |
|
fn = infer, |
|
inputs = [prompt], |
|
outputs = [result] |
|
) |
|
|
|
demo.queue().launch() |