Spaces:
Building
on
A10G
Building
on
A10G
Update diffusion_webui/stable_diffusion/keras_txt2img.py
Browse files
diffusion_webui/stable_diffusion/keras_txt2img.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from huggingface_hub import from_pretrained_keras
|
2 |
from keras_cv import models
|
3 |
from tensorflow import keras
|
4 |
-
|
5 |
import gradio as gr
|
6 |
|
7 |
stable_model_list = [
|
@@ -27,23 +27,24 @@ def keras_stable_diffusion(
|
|
27 |
height:int,
|
28 |
width:int,
|
29 |
):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
sd_dreambooth_model = models.StableDiffusion(
|
34 |
-
img_width=height,
|
35 |
-
img_height=width
|
36 |
-
)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
return generated_images
|
49 |
|
|
|
1 |
from huggingface_hub import from_pretrained_keras
|
2 |
from keras_cv import models
|
3 |
from tensorflow import keras
|
4 |
+
import tensorflow as tf
|
5 |
import gradio as gr
|
6 |
|
7 |
stable_model_list = [
|
|
|
27 |
height:int,
|
28 |
width:int,
|
29 |
):
|
30 |
+
|
31 |
+
with tf.device('/GPU:0'):
|
32 |
+
keras.mixed_precision.set_global_policy("mixed_float16")
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
sd_dreambooth_model = models.StableDiffusion(
|
35 |
+
img_width=height,
|
36 |
+
img_height=width
|
37 |
+
)
|
38 |
+
|
39 |
+
db_diffusion_model = from_pretrained_keras(model_path)
|
40 |
+
sd_dreambooth_model._diffusion_model = db_diffusion_model
|
41 |
+
|
42 |
+
generated_images = sd_dreambooth_model.text_to_image(
|
43 |
+
prompt=prompt,
|
44 |
+
negative_prompt=negative_prompt,
|
45 |
+
num_steps=num_inference_step,
|
46 |
+
unconditional_guidance_scale=guidance_scale
|
47 |
+
)
|
48 |
|
49 |
return generated_images
|
50 |
|