Spaces:
Build error
Build error
change image layout.
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import time
|
|
11 |
|
12 |
import gradio as gr
|
13 |
import keras_cv
|
|
|
14 |
|
15 |
from constants import css, examples, img_height, img_width, num_images_to_gen
|
16 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
@@ -29,10 +30,7 @@ pokemon_model.decoder.compile(jit_compile=True)
|
|
29 |
pokemon_model.text_encoder.compile(jit_compile=True)
|
30 |
|
31 |
# Warm-up the model.
|
32 |
-
_ = pokemon_model.text_to_image(
|
33 |
-
"Teddy bear",
|
34 |
-
batch_size=num_images_to_gen,
|
35 |
-
)
|
36 |
|
37 |
|
38 |
def generate_image_fn(prompt: str, unconditional_guidance_scale: int) -> list:
|
@@ -43,9 +41,14 @@ def generate_image_fn(prompt: str, unconditional_guidance_scale: int) -> list:
|
|
43 |
unconditional_guidance_scale=unconditional_guidance_scale,
|
44 |
)
|
45 |
end_time = time.time()
|
|
|
46 |
print(f"Time taken: {end_time - start_time} seconds.")
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
block = gr.Blocks(css=css)
|
@@ -128,9 +131,7 @@ with block:
|
|
128 |
label="Guidance Scale", minimum=10, maximum=50, value=40, step=1.0
|
129 |
)
|
130 |
btn = gr.Button("Generate image").style(
|
131 |
-
margin=False,
|
132 |
-
rounded=(False, True, True, False),
|
133 |
-
full_width=False,
|
134 |
)
|
135 |
|
136 |
gallery = gr.Gallery(
|
@@ -157,16 +158,11 @@ with block:
|
|
157 |
outputs=[gallery],
|
158 |
postprocess=False,
|
159 |
)
|
160 |
-
share_button.click(
|
161 |
-
None,
|
162 |
-
[],
|
163 |
-
[],
|
164 |
-
_js=share_js,
|
165 |
-
)
|
166 |
gr.HTML(
|
167 |
"""
|
168 |
<div class="footer">
|
169 |
-
<p>For details on the fine-tuning procedure, check out the <a style="text-decoration: underline;" href="https://github.com/sayakpaul/stable-diffusion-keras-ft/">corresponding repository</a>.
|
170 |
</div>
|
171 |
<div class="acknowledgments">
|
172 |
<p><h4>LICENSE</h4>
|
|
|
11 |
|
12 |
import gradio as gr
|
13 |
import keras_cv
|
14 |
+
from PIL import Image
|
15 |
|
16 |
from constants import css, examples, img_height, img_width, num_images_to_gen
|
17 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
|
|
30 |
pokemon_model.text_encoder.compile(jit_compile=True)
|
31 |
|
32 |
# Warm-up the model.
|
33 |
+
_ = pokemon_model.text_to_image("Teddy bear", batch_size=num_images_to_gen)
|
|
|
|
|
|
|
34 |
|
35 |
|
36 |
def generate_image_fn(prompt: str, unconditional_guidance_scale: int) -> list:
|
|
|
41 |
unconditional_guidance_scale=unconditional_guidance_scale,
|
42 |
)
|
43 |
end_time = time.time()
|
44 |
+
image_paths = []
|
45 |
print(f"Time taken: {end_time - start_time} seconds.")
|
46 |
+
for i in range(len(images)):
|
47 |
+
filename = f"prompt_{i}.png"
|
48 |
+
image = Image.fromarray(images[i])
|
49 |
+
image.save(filename)
|
50 |
+
image_paths.append(filename)
|
51 |
+
return image_paths
|
52 |
|
53 |
|
54 |
block = gr.Blocks(css=css)
|
|
|
131 |
label="Guidance Scale", minimum=10, maximum=50, value=40, step=1.0
|
132 |
)
|
133 |
btn = gr.Button("Generate image").style(
|
134 |
+
margin=False, rounded=(False, True, True, False), full_width=False
|
|
|
|
|
135 |
)
|
136 |
|
137 |
gallery = gr.Gallery(
|
|
|
158 |
outputs=[gallery],
|
159 |
postprocess=False,
|
160 |
)
|
161 |
+
share_button.click(None, [], [], _js=share_js)
|
|
|
|
|
|
|
|
|
|
|
162 |
gr.HTML(
|
163 |
"""
|
164 |
<div class="footer">
|
165 |
+
<p>For details on the fine-tuning procedure, check out the <a style="text-decoration: underline;" href="https://github.com/sayakpaul/stable-diffusion-keras-ft/">corresponding repository</a>. The generated images may not be very impressive as the underlying model is still being fine-tuned as of this writing. Since this Space is running on a Tesla T4 GPU, we took advantage of mixed-precision for optimized inference. Additionally, we leveraged XLA to carve out maximum performance from TensorFlow. The front-end of this Space is adapted from the <a style="text-decoration: underline;" href="https://huggingface.co/spaces/stabilityai/stable-diffusion">original Stable Diffusion 2.1 Space</a>.</p>
|
166 |
</div>
|
167 |
<div class="acknowledgments">
|
168 |
<p><h4>LICENSE</h4>
|