from huggingface_hub import from_pretrained_keras
import keras_cv
import gradio as gr
from tensorflow import keras
keras.mixed_precision.set_global_policy("mixed_float16")
# load keras model
resolution = 256
dreambooth_model = keras_cv.models.StableDiffusion(
img_width=resolution, img_height=resolution, jit_compile=True,
)
loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/dreambooth-piranesi")
dreambooth_model._diffusion_model = loaded_diffusion_model
def generate_images(prompt: str, negative_prompt:str, num_imgs_to_gen: int, ugs: int):
generated_img = 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.HTML("
Dreambooth Piranesi Art
")
with gr.Row():
with gr.Column():
prompt = gr.Textbox(lines=1, value="image of monuments in sks style", label="Base Prompt")
negative_prompt = gr.Textbox(lines=1, value="deformed", label="Negative Prompt")
samples = gr.Slider(minimum=1, maximum=5, default=1, step=1, label="Number of Image")
num_steps = gr.Slider(label="Inference Steps",value=75)
ugs = gr.Slider(default=15, minimum=5, maximum=25, step=1, label="Unconditional Guidance Scale")
run = gr.Button(value="Run")
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([["image of monuments in sks style, 8k, high quality, old paper","deformed", 1, 75, 15]],
[prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images)
demo.launch(debug=True)