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, and can be found in [AmpleBasis/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=1, step=1, label="Number of Images") num_steps = gr.Slider(label="Steps",value=40) ugs = gr.Slider(value=7, minimum=5, maximum=25, step=1, label="Unconditional Guidance Scale") 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",1, 40, 7]], [prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images) demo.launch(debug=True)