from huggingface_hub import from_pretrained_keras from 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/ignatius") dreambooth_model._diffusion_model = loaded_diffusion_model # generate images def generate_images(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale): """ 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. negative_prompt (srt): The text to eliminate from the generation some concepts. num_imgs_to_gen (int): The number of images to be generated using given prompt. num_steps (int): The number of denoising steps guidance_scale (double): Increasing guidance makes generation follow more closely to the prompt. Returns: generated_img (List): List of images that were generated using the model """ generated_images = sd_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_images with gr.Blocks() as demo: gr.HTML("