Spaces:
Runtime error
Runtime error
Use TAESD
Browse files
app.py
CHANGED
|
@@ -9,11 +9,14 @@ import gradio as gr
|
|
| 9 |
import numpy as np
|
| 10 |
import PIL.Image
|
| 11 |
|
|
|
|
| 12 |
from diffusers import DiffusionPipeline
|
| 13 |
|
| 14 |
from lcm_scheduler import LCMScheduler
|
| 15 |
from lcm_ov_pipeline import OVLatentConsistencyModelPipeline
|
| 16 |
|
|
|
|
|
|
|
| 17 |
import os
|
| 18 |
from tqdm import tqdm
|
| 19 |
import gradio_user_history as gr_user_history
|
|
@@ -38,8 +41,20 @@ width = int(os.getenv("IMAGE_WIDTH", "512"))
|
|
| 38 |
height = int(os.getenv("IMAGE_HEIGHT", "512"))
|
| 39 |
num_images = int(os.getenv("NUM_IMAGES", "1"))
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
scheduler = LCMScheduler.from_pretrained(model_id, subfolder="scheduler")
|
| 42 |
pipe = OVLatentConsistencyModelPipeline.from_pretrained(model_id, scheduler = scheduler, compile = False, ov_config = {"CACHE_DIR":""})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
pipe.reshape(batch_size=batch_size, height=height, width=width, num_images_per_prompt=num_images)
|
| 44 |
pipe.compile()
|
| 45 |
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
import PIL.Image
|
| 11 |
|
| 12 |
+
from huggingface_hub import snapshot_download
|
| 13 |
from diffusers import DiffusionPipeline
|
| 14 |
|
| 15 |
from lcm_scheduler import LCMScheduler
|
| 16 |
from lcm_ov_pipeline import OVLatentConsistencyModelPipeline
|
| 17 |
|
| 18 |
+
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel
|
| 19 |
+
|
| 20 |
import os
|
| 21 |
from tqdm import tqdm
|
| 22 |
import gradio_user_history as gr_user_history
|
|
|
|
| 41 |
height = int(os.getenv("IMAGE_HEIGHT", "512"))
|
| 42 |
num_images = int(os.getenv("NUM_IMAGES", "1"))
|
| 43 |
|
| 44 |
+
class CustomOVModelVaeDecoder(OVModelVaeDecoder):
|
| 45 |
+
def __init__(
|
| 46 |
+
self, model: openvino.runtime.Model, parent_model: OVBaseModel, ov_config: Optional[Dict[str, str]] = None, model_dir: str = None,
|
| 47 |
+
):
|
| 48 |
+
super(OVModelVaeDecoder, self).__init__(model, parent_model, ov_config, "vae_decoder", model_dir)
|
| 49 |
+
|
| 50 |
scheduler = LCMScheduler.from_pretrained(model_id, subfolder="scheduler")
|
| 51 |
pipe = OVLatentConsistencyModelPipeline.from_pretrained(model_id, scheduler = scheduler, compile = False, ov_config = {"CACHE_DIR":""})
|
| 52 |
+
|
| 53 |
+
# Inject TAESD
|
| 54 |
+
|
| 55 |
+
taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
|
| 56 |
+
pipe.vae_decoder = CustomOVModelVaeDecoder(model = OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"), parent_model = pipe, model_dir = taesd_dir)
|
| 57 |
+
|
| 58 |
pipe.reshape(batch_size=batch_size, height=height, width=width, num_images_per_prompt=num_images)
|
| 59 |
pipe.compile()
|
| 60 |
|