Spaces:
Build error
Build error
Commit
·
2b7c6f5
1
Parent(s):
2337d90
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import gradio as gr
|
|
| 2 |
from optimum.intel.openvino import OVStableDiffusionPipeline
|
| 3 |
from diffusers.training_utils import set_seed
|
| 4 |
|
|
|
|
|
|
|
| 5 |
pipe_fp32 = OVStableDiffusionPipeline.from_pretrained("OpenVINO/stable-diffusion-pokemons-fp32", compile=False)
|
| 6 |
pipe_fp32.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
| 7 |
pipe_fp32.compile()
|
|
@@ -24,8 +26,10 @@ pipes = {
|
|
| 24 |
|
| 25 |
def generate(image, option):
|
| 26 |
pipe = pipes[option]
|
|
|
|
| 27 |
output = pipe(prompt, num_inference_steps=50, output_type="pil")
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
examples = ["cartoon bird",
|
| 31 |
"a drawing of a green pokemon with red eyes",
|
|
@@ -36,8 +40,8 @@ gr.Interface(
|
|
| 36 |
inputs=[gr.inputs.Textbox(placeholder="cartoon bird", label="Prompt", lines=1),
|
| 37 |
gr.inputs.Dropdown(choices=[option for option in pipes.keys()], default="Merged and quantized", label="Model version"),
|
| 38 |
],
|
| 39 |
-
outputs=gr.outputs.Image(type="pil", label="Generated Image"),
|
| 40 |
title="OpenVINO-optimized Stable Diffusion",
|
| 41 |
-
description="This is the Optimum-based demo for optimized Stable Diffusion pipeline trained on
|
| 42 |
theme="huggingface",
|
| 43 |
).launch()
|
|
|
|
| 2 |
from optimum.intel.openvino import OVStableDiffusionPipeline
|
| 3 |
from diffusers.training_utils import set_seed
|
| 4 |
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
pipe_fp32 = OVStableDiffusionPipeline.from_pretrained("OpenVINO/stable-diffusion-pokemons-fp32", compile=False)
|
| 8 |
pipe_fp32.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
| 9 |
pipe_fp32.compile()
|
|
|
|
| 26 |
|
| 27 |
def generate(image, option):
|
| 28 |
pipe = pipes[option]
|
| 29 |
+
start_time = time.time()
|
| 30 |
output = pipe(prompt, num_inference_steps=50, output_type="pil")
|
| 31 |
+
elapsed_time = time.time() - start_time
|
| 32 |
+
return (output.images[0], f"Inference time: {elapsed_time}")
|
| 33 |
|
| 34 |
examples = ["cartoon bird",
|
| 35 |
"a drawing of a green pokemon with red eyes",
|
|
|
|
| 40 |
inputs=[gr.inputs.Textbox(placeholder="cartoon bird", label="Prompt", lines=1),
|
| 41 |
gr.inputs.Dropdown(choices=[option for option in pipes.keys()], default="Merged and quantized", label="Model version"),
|
| 42 |
],
|
| 43 |
+
outputs=[gr.outputs.Image(type="pil", label="Generated Image"), "text"],
|
| 44 |
title="OpenVINO-optimized Stable Diffusion",
|
| 45 |
+
description="This is the Optimum-based demo for NNCF-optimized Stable Diffusion pipeline trained on 'lambdalabs/pokemon-blip-captions' dataset and running with OpenVINO",
|
| 46 |
theme="huggingface",
|
| 47 |
).launch()
|