kadirnar commited on
Commit
0454d85
1 Parent(s): 83d0847

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
- keras.mixed_precision.set_global_policy("mixed_float16")
32
-
33
- sd_dreambooth_model = models.StableDiffusion(
34
- img_width=height,
35
- img_height=width
36
- )
37
 
38
- db_diffusion_model = from_pretrained_keras(model_path)
39
- sd_dreambooth_model._diffusion_model = db_diffusion_model
40
-
41
- generated_images = sd_dreambooth_model.text_to_image(
42
- prompt=prompt,
43
- negative_prompt=negative_prompt,
44
- num_steps=num_inference_step,
45
- unconditional_guidance_scale=guidance_scale
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