|
import gradio as gr |
|
import numpy as np |
|
import random |
|
from diffusers import DiffusionPipeline |
|
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel, OVStableDiffusionPipeline |
|
import torch |
|
from huggingface_hub import snapshot_download |
|
import openvino.runtime as ov |
|
from typing import Optional, Dict |
|
from diffusers import EulerDiscreteScheduler |
|
|
|
|
|
model_id = "hsuwill000/anything-v5-openvino" |
|
|
|
|
|
HIGH=512 |
|
WIDTH=512 |
|
|
|
batch_size = -1 |
|
|
|
pipe = OVStableDiffusionPipeline.from_pretrained( |
|
model_id, |
|
compile = False, |
|
ov_config = {"CACHE_DIR":""}, |
|
torch_dtype=torch.int8, |
|
|
|
|
|
|
|
safety_checker=None, |
|
use_safetensors=False, |
|
) |
|
pipe.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config) |
|
|
|
|
|
|
|
pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pipe.compile() |
|
|
|
prompt="" |
|
negative_prompt="(worst quality, low quality, lowres, ), zombie, interlocked fingers, large breasts, username, watermark," |
|
|
|
def infer(prompt,negative_prompt): |
|
|
|
image = pipe( |
|
prompt = prompt, |
|
negative_prompt = negative_prompt, |
|
width = WIDTH, |
|
height = HIGH, |
|
guidance_scale=7.5, |
|
num_inference_steps=26, |
|
num_images_per_prompt=1, |
|
).images[0] |
|
|
|
return image |
|
|
|
|
|
examples = [ |
|
"Sailor Chibi Moon, Katsura Masakazu style,close-up,", |
|
"1girl, silver hair, symbol-shaped pupils, yellow eyes, smiling, light particles, light rays, wallpaper, star guardian, serious face, red inner hair, power aura, grandmaster1, golden and white clothes", |
|
"masterpiece, best quality, highres booru, 1girl, solo, depth of field, rim lighting, flowers, petals, from above, crystals, butterfly, vegetation, aura, magic, hatsune miku, blush, slight smile, close-up, against wall,", |
|
"(illustration, 8k CG, extremely detailed),(whimsical),catgirl,teenage girl,playing in the snow,winter wonderland,snow-covered trees,soft pastel colors,gentle lighting,sparkling snow,joyful,magical atmosphere,highly detailed,fluffy cat ears and tail,intricate winter clothing,shallow depth of field,watercolor techniques,close-up shot,slightly tilted angle,fairy tale architecture,nostalgic,playful,winter magic,(masterpiece:2),best quality,ultra highres,original,extremely detailed,perfect lighting,", |
|
] |
|
|
|
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""" |
|
# anything-v5-openvino {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) |
|
|
|
gr.Examples( |
|
examples = examples, |
|
fn = infer, |
|
inputs = [prompt], |
|
outputs = [result] |
|
) |
|
|
|
run_button.click( |
|
fn = infer, |
|
inputs = [prompt], |
|
outputs = [result] |
|
) |
|
|
|
demo.queue().launch() |