Spaces:
Build error
Build error
Commit
·
ad14b11
1
Parent(s):
e12048f
Added torch model
Browse files
app.py
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from optimum.intel.openvino import OVStableDiffusionPipeline
|
| 3 |
from diffusers.training_utils import set_seed
|
| 4 |
-
from diffusers import LMSDiscreteScheduler
|
| 5 |
|
| 6 |
import time
|
| 7 |
|
| 8 |
-
scheduler =
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
pipe_fp32.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
| 12 |
pipe_fp32.compile()
|
| 13 |
|
|
@@ -22,9 +24,10 @@ pipe_tome_int8.compile()
|
|
| 22 |
prompt = "cartoon bird"
|
| 23 |
|
| 24 |
pipes = {
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
-
"
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
def generate(image, option):
|
|
@@ -38,10 +41,12 @@ examples = ["cartoon bird",
|
|
| 38 |
"a drawing of a green pokemon with red eyes",
|
| 39 |
"plant pokemon in jungle"]
|
| 40 |
|
|
|
|
|
|
|
| 41 |
gr.Interface(
|
| 42 |
fn=generate,
|
| 43 |
inputs=[gr.inputs.Textbox(placeholder="cartoon bird", label="Prompt", lines=1),
|
| 44 |
-
gr.inputs.Dropdown(choices=
|
| 45 |
],
|
| 46 |
outputs=[gr.outputs.Image(type="pil", label="Generated Image"), gr.outputs.Textbox(label="Inference time")],
|
| 47 |
title="OpenVINO-optimized Stable Diffusion",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from optimum.intel.openvino import OVStableDiffusionPipeline
|
| 3 |
from diffusers.training_utils import set_seed
|
| 4 |
+
from diffusers import LMSDiscreteScheduler, StableDiffusionPipeline
|
| 5 |
|
| 6 |
import time
|
| 7 |
|
| 8 |
+
# scheduler = DDPMScheduler(beta_start=0.00085, beta_end=0.012,
|
| 9 |
+
# beta_schedule="scaled_linear", num_train_timesteps=1000)
|
| 10 |
+
pipe_torch_fp32 = StableDiffusionPipeline("svjack/Stable-Diffusion-Pokemon-en")
|
| 11 |
+
|
| 12 |
+
pipe_fp32 = OVStableDiffusionPipeline.from_pretrained("OpenVINO/stable-diffusion-pokemons-fp32", compile=False) scheduler=scheduler)
|
| 13 |
pipe_fp32.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
| 14 |
pipe_fp32.compile()
|
| 15 |
|
|
|
|
| 24 |
prompt = "cartoon bird"
|
| 25 |
|
| 26 |
pipes = {
|
| 27 |
+
"Torch fp32"
|
| 28 |
+
"OpenVINO fp32": pipe_fp32,
|
| 29 |
+
"OpenVINO 8-bit quantized": pipe_int8,
|
| 30 |
+
"OpenVINO merged and quantized": pipe_tome_int8
|
| 31 |
}
|
| 32 |
|
| 33 |
def generate(image, option):
|
|
|
|
| 41 |
"a drawing of a green pokemon with red eyes",
|
| 42 |
"plant pokemon in jungle"]
|
| 43 |
|
| 44 |
+
choices = [option for option in pipes.keys()]
|
| 45 |
+
|
| 46 |
gr.Interface(
|
| 47 |
fn=generate,
|
| 48 |
inputs=[gr.inputs.Textbox(placeholder="cartoon bird", label="Prompt", lines=1),
|
| 49 |
+
gr.inputs.Dropdown(choices=choices], default=choices[-1], label="Model version"),
|
| 50 |
],
|
| 51 |
outputs=[gr.outputs.Image(type="pil", label="Generated Image"), gr.outputs.Textbox(label="Inference time")],
|
| 52 |
title="OpenVINO-optimized Stable Diffusion",
|