Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
import gc
|
3 |
|
4 |
-
pipe = StableDiffusionPipeline.from_pretrained("
|
5 |
text_encoder = pipe.text_encoder
|
6 |
text_encoder.eval()
|
7 |
unet = pipe.unet
|
@@ -43,7 +43,6 @@ def convert_encoder(text_encoder:torch.nn.Module,ir_path:Path):
|
|
43 |
del ov_model
|
44 |
cleanup_cache()
|
45 |
print(f"Text Encoder successfully converted to TR and saved to {ir_path}")
|
46 |
-
|
47 |
if not text_encoder_path.exists():
|
48 |
convert_encoder(text_encoder,text_encoder_path)
|
49 |
else:
|
@@ -425,8 +424,8 @@ class OVStableDiffusionPipeline(DiffusionPipeline):
|
|
425 |
|
426 |
return timesteps, num_inference_steps - t_start
|
427 |
|
428 |
-
core=pv.Core()
|
429 |
|
|
|
430 |
import ipywidgets as widgets
|
431 |
device=widgets.Dropdown(
|
432 |
options=core.available_devices+["AUTO"],
|
@@ -435,11 +434,12 @@ device=widgets.Dropdown(
|
|
435 |
disabled=False,
|
436 |
)
|
437 |
device
|
438 |
-
|
439 |
-
|
440 |
text_enc=core.compile_model(text_encoder_path,device.value)
|
441 |
-
|
442 |
unet_model=core.compile_model(unet_path,device.value)
|
|
|
|
|
|
|
|
|
443 |
from transformers import CLIPTokenizer
|
444 |
from diffusers.schedulers import LMSDiscreteScheduler
|
445 |
lms=LMSDiscreteScheduler(
|
@@ -455,6 +455,13 @@ pv_pipe=OVStableDiffusionPipeline(
|
|
455 |
vae_encoder=vae_encoder,
|
456 |
vae_decoder=vae_decoder,
|
457 |
scheduler=lms)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
import gradio as gr
|
460 |
|
@@ -479,5 +486,4 @@ with gr.Blocks() as demo:
|
|
479 |
try:
|
480 |
demo.queue().launch(debug=True)
|
481 |
except Exception:
|
482 |
-
demo.queue().launch(share=True,debug=True)
|
483 |
-
|
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
import gc
|
3 |
|
4 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to("cpu")
|
5 |
text_encoder = pipe.text_encoder
|
6 |
text_encoder.eval()
|
7 |
unet = pipe.unet
|
|
|
43 |
del ov_model
|
44 |
cleanup_cache()
|
45 |
print(f"Text Encoder successfully converted to TR and saved to {ir_path}")
|
|
|
46 |
if not text_encoder_path.exists():
|
47 |
convert_encoder(text_encoder,text_encoder_path)
|
48 |
else:
|
|
|
424 |
|
425 |
return timesteps, num_inference_steps - t_start
|
426 |
|
|
|
427 |
|
428 |
+
core=pv.Core()
|
429 |
import ipywidgets as widgets
|
430 |
device=widgets.Dropdown(
|
431 |
options=core.available_devices+["AUTO"],
|
|
|
434 |
disabled=False,
|
435 |
)
|
436 |
device
|
|
|
|
|
437 |
text_enc=core.compile_model(text_encoder_path,device.value)
|
|
|
438 |
unet_model=core.compile_model(unet_path,device.value)
|
439 |
+
|
440 |
+
pv_config={"INFERENCE_PRECISION_HINT":"f32"}if device.value !="CPU" else {}
|
441 |
+
vae_decoder=core.compile_model(VAE_DECODER_PATH,device.value,pv_config)
|
442 |
+
vae_encoder=core.compile_model(VAE_ENCODER_PATH,device.value,pv_config)
|
443 |
from transformers import CLIPTokenizer
|
444 |
from diffusers.schedulers import LMSDiscreteScheduler
|
445 |
lms=LMSDiscreteScheduler(
|
|
|
455 |
vae_encoder=vae_encoder,
|
456 |
vae_decoder=vae_decoder,
|
457 |
scheduler=lms)
|
458 |
+
from ipywidgets import widgets
|
459 |
+
sample_text=("A Dog wearing golden rich mens necklace")
|
460 |
+
text_prompt=widgets.Text(value=sample_text,description="A Dog wearing golden rich mens necklace ")
|
461 |
+
num_steps=widgets.IntSlider(min=1,max=50,value=20,description="steps:")
|
462 |
+
seed=widgets.IntSlider(min=0,max=10000000,description="seed:",value=54)
|
463 |
+
widgets.VBox([text_prompt,seed,num_steps])
|
464 |
+
result=pv_pipe(text_prompt.value,num_inference_steps=num_steps.value,seed=seed.value)
|
465 |
|
466 |
import gradio as gr
|
467 |
|
|
|
486 |
try:
|
487 |
demo.queue().launch(debug=True)
|
488 |
except Exception:
|
489 |
+
demo.queue().launch(share=True,debug=True)
|
|