Spaces:
Build error
Build error
Upload 3 files
Browse files- app.py +25 -3
- keras_txt2img.py +116 -0
- requirements.txt +5 -1
app.py
CHANGED
@@ -9,14 +9,20 @@ from diffusion_webui.controlnet.controlnet_seg import stable_diffusion_controlne
|
|
9 |
from diffusion_webui.stable_diffusion.text2img_app import stable_diffusion_text2img_app, stable_diffusion_text2img
|
10 |
from diffusion_webui.stable_diffusion.img2img_app import stable_diffusion_img2img_app, stable_diffusion_img2img
|
11 |
from diffusion_webui.stable_diffusion.inpaint_app import stable_diffusion_inpaint_app, stable_diffusion_inpaint
|
|
|
12 |
|
13 |
|
14 |
import gradio as gr
|
15 |
|
16 |
-
|
17 |
app = gr.Blocks()
|
18 |
with app:
|
19 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
gr.Markdown(
|
21 |
"""
|
22 |
<h4 style='text-align: center'>
|
@@ -39,7 +45,8 @@ with app:
|
|
39 |
controlnet_pose_app = stable_diffusion_controlnet_pose_app()
|
40 |
controlnet_scribble_app = stable_diffusion_controlnet_scribble_app()
|
41 |
controlnet_seg_app = stable_diffusion_controlnet_seg_app()
|
42 |
-
|
|
|
43 |
|
44 |
with gr.Tab('Output'):
|
45 |
with gr.Column():
|
@@ -175,5 +182,20 @@ with app:
|
|
175 |
],
|
176 |
outputs = [output_image],
|
177 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
app.launch(debug=True)
|
|
|
9 |
from diffusion_webui.stable_diffusion.text2img_app import stable_diffusion_text2img_app, stable_diffusion_text2img
|
10 |
from diffusion_webui.stable_diffusion.img2img_app import stable_diffusion_img2img_app, stable_diffusion_img2img
|
11 |
from diffusion_webui.stable_diffusion.inpaint_app import stable_diffusion_inpaint_app, stable_diffusion_inpaint
|
12 |
+
from diffusion_webui.stable_diffusion.keras_txt2img import keras_stable_diffusion, keras_stable_diffusion_app
|
13 |
|
14 |
|
15 |
import gradio as gr
|
16 |
|
|
|
17 |
app = gr.Blocks()
|
18 |
with app:
|
19 |
+
gr.HTML(
|
20 |
+
"""
|
21 |
+
<h1 style='text-align: center'>
|
22 |
+
Stable Diffusion + ControlNet WebUI
|
23 |
+
</h1>
|
24 |
+
"""
|
25 |
+
)
|
26 |
gr.Markdown(
|
27 |
"""
|
28 |
<h4 style='text-align: center'>
|
|
|
45 |
controlnet_pose_app = stable_diffusion_controlnet_pose_app()
|
46 |
controlnet_scribble_app = stable_diffusion_controlnet_scribble_app()
|
47 |
controlnet_seg_app = stable_diffusion_controlnet_seg_app()
|
48 |
+
|
49 |
+
keras_diffusion_app = keras_stable_diffusion_app()
|
50 |
|
51 |
with gr.Tab('Output'):
|
52 |
with gr.Column():
|
|
|
182 |
],
|
183 |
outputs = [output_image],
|
184 |
)
|
185 |
+
|
186 |
+
keras_diffusion_app['predict'].click(
|
187 |
+
fn = keras_stable_diffusion,
|
188 |
+
inputs = [
|
189 |
+
keras_diffusion_app['model_path'],
|
190 |
+
keras_diffusion_app['prompt'],
|
191 |
+
keras_diffusion_app['negative_prompt'],
|
192 |
+
keras_diffusion_app['guidance_scale'],
|
193 |
+
keras_diffusion_app['num_inference_step'],
|
194 |
+
keras_diffusion_app['height'],
|
195 |
+
keras_diffusion_app['width'],
|
196 |
+
],
|
197 |
+
outputs = [output_image],
|
198 |
+
)
|
199 |
+
|
200 |
|
201 |
app.launch(debug=True)
|
keras_txt2img.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = [
|
8 |
+
"keras-dreambooth/dreambooth_diffusion_model"
|
9 |
+
]
|
10 |
+
|
11 |
+
stable_prompt_list = [
|
12 |
+
"a photo of a man.",
|
13 |
+
"a photo of a girl."
|
14 |
+
]
|
15 |
+
|
16 |
+
stable_negative_prompt_list = [
|
17 |
+
"bad, ugly",
|
18 |
+
"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 |
+
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 |
+
|
50 |
+
def keras_stable_diffusion_app():
|
51 |
+
with gr.Tab('Keras Diffusion'):
|
52 |
+
keras_text2image_model_path = gr.Dropdown(
|
53 |
+
choices=stable_model_list,
|
54 |
+
value=stable_model_list[0],
|
55 |
+
label='Text-Image Model Id'
|
56 |
+
)
|
57 |
+
|
58 |
+
keras_text2image_prompt = gr.Textbox(
|
59 |
+
lines=1,
|
60 |
+
value=stable_prompt_list[0],
|
61 |
+
label='Prompt'
|
62 |
+
)
|
63 |
+
|
64 |
+
keras_text2image_negative_prompt = gr.Textbox(
|
65 |
+
lines=1,
|
66 |
+
value=stable_negative_prompt_list[0],
|
67 |
+
label='Negative Prompt'
|
68 |
+
)
|
69 |
+
|
70 |
+
with gr.Accordion("Advanced Options", open=False):
|
71 |
+
keras_text2image_guidance_scale = gr.Slider(
|
72 |
+
minimum=0.1,
|
73 |
+
maximum=15,
|
74 |
+
step=0.1,
|
75 |
+
value=7.5,
|
76 |
+
label='Guidance Scale'
|
77 |
+
)
|
78 |
+
|
79 |
+
keras_text2image_num_inference_step = gr.Slider(
|
80 |
+
minimum=1,
|
81 |
+
maximum=100,
|
82 |
+
step=1,
|
83 |
+
value=50,
|
84 |
+
label='Num Inference Step'
|
85 |
+
)
|
86 |
+
|
87 |
+
keras_text2image_height = gr.Slider(
|
88 |
+
minimum=128,
|
89 |
+
maximum=1280,
|
90 |
+
step=32,
|
91 |
+
value=512,
|
92 |
+
label='Image Height'
|
93 |
+
)
|
94 |
+
|
95 |
+
keras_text2image_width = gr.Slider(
|
96 |
+
minimum=128,
|
97 |
+
maximum=1280,
|
98 |
+
step=32,
|
99 |
+
value=768,
|
100 |
+
label='Image Height'
|
101 |
+
)
|
102 |
+
|
103 |
+
keras_text2image_predict = gr.Button(value='Generator')
|
104 |
+
|
105 |
+
variables = {
|
106 |
+
"model_path": keras_text2image_model_path,
|
107 |
+
"prompt": keras_text2image_prompt,
|
108 |
+
"negative_prompt": keras_text2image_negative_prompt,
|
109 |
+
"guidance_scale": keras_text2image_guidance_scale,
|
110 |
+
"num_inference_step": keras_text2image_num_inference_step,
|
111 |
+
"height": keras_text2image_height,
|
112 |
+
"width": keras_text2image_width,
|
113 |
+
"predict": keras_text2image_predict
|
114 |
+
}
|
115 |
+
|
116 |
+
return variables
|
requirements.txt
CHANGED
@@ -5,4 +5,8 @@ controlnet_aux
|
|
5 |
diffusers
|
6 |
imageio
|
7 |
gradio
|
8 |
-
triton
|
|
|
|
|
|
|
|
|
|
5 |
diffusers
|
6 |
imageio
|
7 |
gradio
|
8 |
+
triton
|
9 |
+
tensorflow
|
10 |
+
huggingface-hub
|
11 |
+
keras-cv
|
12 |
+
pycocotools
|