kadirnar commited on
Commit
7b96e45
1 Parent(s): 31edd76
diffusion_webui/stable_diffusion/__pycache__/__init__.cpython-38.pyc DELETED
Binary file (191 Bytes)
 
diffusion_webui/stable_diffusion/__pycache__/img2img_app.cpython-38.pyc DELETED
Binary file (2.55 kB)
 
diffusion_webui/stable_diffusion/__pycache__/inpaint_app.cpython-38.pyc DELETED
Binary file (2.42 kB)
 
diffusion_webui/stable_diffusion/__pycache__/keras_txt2img.cpython-38.pyc DELETED
Binary file (2.79 kB)
 
diffusion_webui/stable_diffusion/__pycache__/text2img_app.cpython-38.pyc DELETED
Binary file (2.74 kB)
 
diffusion_webui/stable_diffusion/inpaint_app.py CHANGED
@@ -8,7 +8,6 @@ stable_inpiant_model_list = [
8
  ]
9
 
10
  stable_prompt_list = ["a photo of a man.", "a photo of a girl."]
11
-
12
  stable_negative_prompt_list = ["bad, ugly", "deformed"]
13
 
14
 
 
8
  ]
9
 
10
  stable_prompt_list = ["a photo of a man.", "a photo of a girl."]
 
11
  stable_negative_prompt_list = ["bad, ugly", "deformed"]
12
 
13
 
diffusion_webui/stable_diffusion/keras_txt2img.py CHANGED
@@ -1,51 +1,55 @@
1
  import gradio as gr
2
- import tensorflow as tf
3
  from huggingface_hub import from_pretrained_keras
4
  from keras_cv import models
5
  from tensorflow import keras
6
 
7
  keras_model_list = [
8
  "keras-dreambooth/keras_diffusion_lowpoly_world",
9
- "keras-dreambooth/pink-floyd-division-bell",
10
- "keras-dreambooth/dreambooth_diffusion_model",
11
  ]
12
 
13
  stable_prompt_list = [
14
- "a photo of lowpoly_world",
15
- "Flower vase inspired by pink floyd division bell",
16
  ]
17
 
18
  stable_negative_prompt_list = ["bad, ugly", "deformed"]
19
 
 
 
 
 
 
 
 
20
 
21
  def keras_stable_diffusion(
22
  model_path: str,
23
  prompt: str,
24
  negative_prompt: str,
25
- guidance_scale: int,
26
- num_inference_step: int,
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, 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
 
50
 
51
  def keras_stable_diffusion_app():
@@ -68,43 +72,26 @@ def keras_stable_diffusion_app():
68
  label="Negative Prompt",
69
  )
70
 
71
- with gr.Accordion("Advanced Options", open=False):
72
- keras_text2image_guidance_scale = gr.Slider(
73
- minimum=0.1,
74
- maximum=15,
75
- step=0.1,
76
- value=7.5,
77
- label="Guidance Scale",
78
- )
79
-
80
- keras_text2image_num_inference_step = gr.Slider(
81
- minimum=1,
82
- maximum=100,
83
- step=1,
84
- value=50,
85
- label="Num Inference Step",
86
- )
87
-
88
- keras_text2image_height = gr.Slider(
89
- minimum=128,
90
- maximum=1280,
91
- step=32,
92
- value=512,
93
- label="Image Height",
94
- )
95
-
96
- keras_text2image_width = gr.Slider(
97
- minimum=128,
98
- maximum=1280,
99
- step=32,
100
- value=512,
101
- label="Image Height",
102
- )
103
 
104
  keras_text2image_predict = gr.Button(value="Generator")
105
 
106
  with gr.Column():
107
- output_image = gr.Gallery(label="Output")
108
 
109
  gr.Examples(
110
  fn=keras_stable_diffusion,
@@ -114,8 +101,6 @@ def keras_stable_diffusion_app():
114
  keras_text2image_negative_prompt,
115
  keras_text2image_guidance_scale,
116
  keras_text2image_num_inference_step,
117
- keras_text2image_height,
118
- keras_text2image_width,
119
  ],
120
  outputs=[output_image],
121
  examples=[
@@ -141,8 +126,6 @@ def keras_stable_diffusion_app():
141
  keras_text2image_negative_prompt,
142
  keras_text2image_guidance_scale,
143
  keras_text2image_num_inference_step,
144
- keras_text2image_height,
145
- keras_text2image_width,
146
  ],
147
  outputs=output_image,
148
  )
 
1
  import gradio as gr
 
2
  from huggingface_hub import from_pretrained_keras
3
  from keras_cv import models
4
  from tensorflow import keras
5
 
6
  keras_model_list = [
7
  "keras-dreambooth/keras_diffusion_lowpoly_world",
8
+ "keras-dreambooth/keras-diffusion-traditional-furniture",
 
9
  ]
10
 
11
  stable_prompt_list = [
12
+ "photo of lowpoly_world",
13
+ "photo of traditional_furniture",
14
  ]
15
 
16
  stable_negative_prompt_list = ["bad, ugly", "deformed"]
17
 
18
+ keras.mixed_precision.set_global_policy("mixed_float16")
19
+ dreambooth_model = models.StableDiffusion(
20
+ img_width=512,
21
+ img_height=512,
22
+ jit_compile=True,
23
+ )
24
+
25
 
26
  def keras_stable_diffusion(
27
  model_path: str,
28
  prompt: str,
29
  negative_prompt: str,
30
+ num_imgs_to_gen: int,
31
+ num_steps: int,
 
 
32
  ):
33
+ """
34
+ This function is used to generate images using our fine-tuned keras dreambooth stable diffusion model.
35
+ Args:
36
+ prompt (str): The text input given by the user based on which images will be generated.
37
+ num_imgs_to_gen (int): The number of images to be generated using given prompt.
38
+ num_steps (int): The number of denoising steps
39
+ Returns:
40
+ generated_img (List): List of images that were generated using the model
41
+ """
42
+ loaded_diffusion_model = from_pretrained_keras(model_path)
43
+ dreambooth_model._diffusion_model = loaded_diffusion_model
44
+
45
+ generated_img = dreambooth_model.text_to_image(
46
+ prompt,
47
+ negative_prompt=negative_prompt,
48
+ batch_size=num_imgs_to_gen,
49
+ num_steps=num_steps,
50
+ )
51
+
52
+ return generated_img
53
 
54
 
55
  def keras_stable_diffusion_app():
 
72
  label="Negative Prompt",
73
  )
74
 
75
+ keras_text2image_guidance_scale = gr.Slider(
76
+ minimum=0.1,
77
+ maximum=15,
78
+ step=0.1,
79
+ value=7.5,
80
+ label="Guidance Scale",
81
+ )
82
+
83
+ keras_text2image_num_inference_step = gr.Slider(
84
+ minimum=1,
85
+ maximum=100,
86
+ step=1,
87
+ value=50,
88
+ label="Num Inference Step",
89
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  keras_text2image_predict = gr.Button(value="Generator")
92
 
93
  with gr.Column():
94
+ output_image = gr.Gallery(label="Outputs").style(grid=(1, 2))
95
 
96
  gr.Examples(
97
  fn=keras_stable_diffusion,
 
101
  keras_text2image_negative_prompt,
102
  keras_text2image_guidance_scale,
103
  keras_text2image_num_inference_step,
 
 
104
  ],
105
  outputs=[output_image],
106
  examples=[
 
126
  keras_text2image_negative_prompt,
127
  keras_text2image_guidance_scale,
128
  keras_text2image_num_inference_step,
 
 
129
  ],
130
  outputs=output_image,
131
  )