File size: 2,447 Bytes
f02a73c
 
 
 
 
 
 
 
 
 
d53ef6d
3f81f99
 
f02a73c
 
 
3f81f99
 
 
 
 
 
 
f02a73c
3f81f99
 
 
 
 
 
 
046d150
3f81f99
 
f02a73c
3f81f99
 
 
 
 
b0c2d2b
 
 
3f81f99
 
 
 
 
 
b0c2d2b
3f81f99
 
f02a73c
3f81f99
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
52
53
54
from huggingface_hub import from_pretrained_keras
from keras_cv import models
import gradio as gr

from tensorflow import keras

keras.mixed_precision.set_global_policy("mixed_float16")

# prepare model
resolution = 512
sd_dreambooth_model = models.StableDiffusion(
        img_width=resolution, img_height=resolution, jit_compile=True, 
    )
db_diffusion_model = from_pretrained_keras("AmpleBasis/seymour-cat")
sd_dreambooth_model._diffusion_model = db_diffusion_model

def generate_images(prompt: str, negative_prompt:str, num_imgs_to_gen: int, num_steps: int, ugs: int):
    generated_img = sd_dreambooth_model.text_to_image(
        prompt, 
        negative_prompt=negative_prompt,
        batch_size=num_imgs_to_gen,
        num_steps=num_steps,
        unconditional_guidance_scale=ugs,
    )
   
    return generated_img
    
with gr.Blocks() as demo:
    gr.Markdown("""
    # Seymour Diffusion
    This is a Keras Dreambooth model fine-tuned to images of Seymour, a cat.
    The model, part of the [Keras Dreambooth Sprint](https://github.com/huggingface/community-events/tree/main/keras-dreambooth-sprint), was trained by [Pedro Pacheco](https://huggingface.co/AmpleBasis), and can be found in [keras-dreambooth/seymour-cat](https://huggingface.co/AmpleBasis/seymour-cat).
    
    The model should be used with a prompt containing `symr cat`. A typical prompt for this model is `photo of symr cat`.
    
    """)
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(lines=1, value="photo of symr cat", label="Prompt")
            negative_prompt = gr.Textbox(lines=1, value="deformed,blurry,lowres", label="Negative Prompt")
            samples = gr.Slider(minimum=1, maximum=5, value=2, step=1, label="Number of Images")
            num_steps = gr.Slider(label="Steps",value=50)
            ugs = gr.Slider(value=7, minimum=5, maximum=25, step=1, label="Guidance Scale: How closely should the images resemble the prompt. Default is 7")
            run = gr.Button(value="Generate")
        with gr.Column():
            gallery = gr.Gallery(label="Outputs").style(grid=(1,2))

    run.click(generate_images, inputs=[prompt,negative_prompt, samples, num_steps, ugs], outputs=gallery)
    
    gr.Examples([["photo of symr cat wearing a pirate costume", "dog,human,deformed,lowres",2, 50, 7]],

                [prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images)

demo.launch(debug=True)