File size: 2,256 Bytes
4f8e447
 
aa1a927
4f8e447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
from huggingface_hub import from_pretrained_keras
import keras_cv
import gradio as gr

def generate_images(prompt: str, num_imgs_to_gen: int):
    """
    This function is used to generate images using our fine-tuned keras dreambooth stable diffusion model.
    Args:
        prompt (str): The text input given by the user based on which images will be generated.
        num_imgs_to_gen (int): The number of images to be generated using given prompt.
    Returns:
        all_images (List): List of images that were generated using the model
    """
    dreambooth_model = keras_cv.models.StableDiffusion(
        img_width=resolution, img_height=resolution, jit_compile=True, 
    )
    loaded_diffusion_model = from_pretrained_keras("shivi/dreambooth_diffusion_model")
    dreambooth_model._diffusion_model = loaded_diffusion_model
    
    generated_img = dreambooth_model.text_to_image(
        prompt, batch_size=num_imgs_to_gen
    )
   
    return generated_img
    

with gr.Blocks() as demo:
    gr.HTML("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\">Keras Dreambooth - Pink Floyd Division Bell Demo</h2>")
    
    gr.Markdown("This model has been fine tuned to learn the concept of Division Bell from Pink Floyd's famous album `The Division Bell`")
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(label="prompt")
            samples = gr.Slider(label="No. of Images",value=1)
            run = gr.Button(value="Run")
        with gr.Column():
            gallery = gr.Gallery(show_label=False)

    run.click(generate_images, inputs=[prompt,samples], outputs=gallery)
    
    gr.Examples([["A flower vase inspired by pink floyd division bell album cover", 1],
                ["A pendant in the style of pink floyd division bell album cover",1],
                ["A human skull inspired by pink floyd division bell album cover ",1],
                ["picture of pink floyd division bell album cover with a starry night on Mars theme", 1]], 
                [prompt,samples,model_choice], gallery, generate_images, cache_examples=True)
    
    gr.Markdown("Some fun examples I created while playing with the model:")
    gr.Makdown("![Example 1](sample_outputs/1.png)")

demo.launch(debug=True)