File size: 2,089 Bytes
d7f77a0
 
 
 
 
 
 
 
 
 
 
ec1e639
d7f77a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c841c4
ec1e639
d7f77a0
2e1b480
ec1e639
d7f77a0
 
 
 
2e1b480
d7f77a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from huggingface_hub import from_pretrained_keras
import keras_cv
import gradio as gr
from tensorflow import keras

keras.mixed_precision.set_global_policy("mixed_float16")
# load keras model
resolution = 512
dreambooth_model = keras_cv.models.StableDiffusion(
        img_width=resolution, img_height=resolution, jit_compile=True, 
    )
loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/monkey_island_style")
dreambooth_model._diffusion_model = loaded_diffusion_model


def generate_images(prompt: str, negative_prompt: str, num_imgs_to_gen: int, num_steps: int, guidance_scale: float):
    generated_img = dreambooth_model.text_to_image(
        prompt, 
        negative_prompt=negative_prompt,
        batch_size=num_imgs_to_gen,
        num_steps=num_steps,
        unconditional_guidance_scale=guidance_scale,
    )

    return generated_img


# pass function, input type for prompt, the output for multiple images
gr.Interface(
    title="Keras Dreambooth - Monkey Island Style πŸ’",
    description="""This SD model has been fine-tuned to learn the art style of the game *Return To Monkey Island* using Dreambooth.
    While not being perfect at imitating the stlye, my experiments have shown that it works best on fictional characters, such as Geralt of Rivia, Frodo Baggins or Harry Potter.
    
    To use the new style make sure to include `in mnky style` to your prompt.
    """,
    fn=generate_images,
    inputs=[
        gr.Textbox(label="Positive Prompt", value="han solo in mnky style, high quality, 4k, trending on artstation"),
        gr.Textbox(label="Negative Prompt", value="bad, ugly"),
        gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
        gr.Slider(label="Inference Steps", value=50),
        gr.Slider(label='Guidance scale', value=7, maximum=15, minimum=0, step=0.5),
    ], 
    outputs=[
        gr.Gallery(show_label=False).style(grid=(1,2)),
    ],
    examples=[["geralt of rivia in mnky style, high quality, 4k, trending on artstation", "bad, ugly", 2, 50, 7]],
    ).queue().launch(debug=True)