Spaces:
Build error
Build error
from huggingface_hub import from_pretrained_keras | |
import keras_cv | |
import gradio as gr | |
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/pink-floyd-division-bell") | |
dreambooth_model._diffusion_model = loaded_diffusion_model | |
def generate_images(prompt: str, num_imgs_to_gen: int, num_steps: 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. | |
num_steps (int): The number of denoising steps | |
Returns: | |
generated_img (List): List of images that were generated using the model | |
""" | |
generated_img = dreambooth_model.text_to_image( | |
prompt, batch_size=num_imgs_to_gen, | |
num_steps=num_steps, | |
) | |
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) | |
num_steps = gr.Slider(label="Inference Steps",value=50) | |
run = gr.Button(value="Run") | |
with gr.Column(): | |
gallery = gr.Gallery(show_label=False) | |
run.click(generate_images, inputs=[prompt,samples, num_steps], outputs=gallery) | |
gr.Examples([["pink floyd division bell album cover with a starry night on Mars background", 1,50], | |
["Flower vase inspired by pink floyd division bell",1, 50], | |
["Pendant jewellery in the style of pink floyd division bell", 1,50]], | |
[prompt,samples,num_steps], gallery, generate_images, cache_examples=False) | |
gr.Markdown('\n Demo created by: <a href=\"https://huggingface.co/shivi/\">Shivalika Singh</a>') | |
demo.launch(debug=True) |