Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,38 @@ from huggingface_hub import from_pretrained_keras
|
|
2 |
from keras_cv import models
|
3 |
import gradio as gr
|
4 |
|
5 |
-
from tensorflow import keras
|
6 |
-
|
7 |
-
keras.mixed_precision.set_global_policy("mixed_float16")
|
8 |
-
|
9 |
-
# prepare model
|
10 |
-
resolution = 512
|
11 |
sd_dreambooth_model = models.StableDiffusion(
|
12 |
-
img_width=
|
13 |
)
|
14 |
db_diffusion_model = from_pretrained_keras("merve/dreambooth_kedis")
|
15 |
sd_dreambooth_model._diffusion_model = db_diffusion_model
|
16 |
|
17 |
# generate images
|
18 |
-
def infer(prompt):
|
19 |
generated_images = sd_dreambooth_model.text_to_image(
|
20 |
-
prompt,
|
|
|
|
|
|
|
|
|
21 |
)
|
22 |
return generated_images
|
23 |
|
24 |
-
|
|
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from keras_cv import models
|
3 |
import gradio as gr
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
sd_dreambooth_model = models.StableDiffusion(
|
6 |
+
img_width=512, img_height=512
|
7 |
)
|
8 |
db_diffusion_model = from_pretrained_keras("merve/dreambooth_kedis")
|
9 |
sd_dreambooth_model._diffusion_model = db_diffusion_model
|
10 |
|
11 |
# generate images
|
12 |
+
def infer(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale):
|
13 |
generated_images = sd_dreambooth_model.text_to_image(
|
14 |
+
prompt,
|
15 |
+
negative_prompt=negative_prompt,
|
16 |
+
batch_size=num_imgs_to_gen,
|
17 |
+
num_steps=num_steps,
|
18 |
+
unconditional_guidance_scale=guidance_scale
|
19 |
)
|
20 |
return generated_images
|
21 |
|
22 |
+
|
23 |
+
# output = gr.Gallery(label="Outputs").style(grid=(2,2))
|
24 |
|
25 |
+
# pass function, input type for prompt, the output for multiple images
|
26 |
+
gr.Interface(
|
27 |
+
infer, [
|
28 |
+
gr.Textbox(label="Positive Prompt", value="a kedis cat as a princess with tiara"),
|
29 |
+
gr.Textbox(label="Negative Prompt", value="bad anatomy, blurry"),
|
30 |
+
gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
|
31 |
+
gr.Slider(label="Inference Steps",value=50),
|
32 |
+
gr.Number(label='Guidance scale', value=7.5),
|
33 |
+
], [
|
34 |
+
gr.Gallery(show_label=False),
|
35 |
+
],
|
36 |
+
title="Dreambooth Kedis",
|
37 |
+
description = "This dreambooth model is fine-tuned on my cat, Kediş (meaning, kitten in Turkish). She's a tabby cat I adopted on a stormy day in the street. You can prompt using the special indicator {kedis cat}.",
|
38 |
+
examples = [["a pencil drawing of a kedis cat as an astronaut", "", 2, 50, 7.5]],
|
39 |
+
).launch()
|