File size: 3,154 Bytes
950728f
753e694
950728f
 
 
 
753e694
2d011e5
753e694
 
 
 
 
950728f
753e694
e371e71
753e694
 
 
 
 
 
950728f
753e694
 
 
 
 
 
 
9de367e
753e694
9de367e
04dc2de
9de367e
753e694
 
 
 
 
950728f
04dc2de
 
 
10d8f0e
 
04dc2de
10d8f0e
 
753e694
950728f
753e694
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
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 = 512
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, num_steps: 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("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\"> Dreambooth Piranesi Art </h2>")    
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(lines=1, value="image of monument in sks style", label="Base Prompt")
            negative_prompt = gr.Textbox(lines=1, value="deformed", label="Negative Prompt")
            samples = gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of Image")
            num_steps = gr.Slider(label="Inference Steps",value=40)
            ugs = gr.Slider(value=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 monument in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 30, 18],
                 ["image of menhir in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 40, 20],
                 ["image of church in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 40, 20],
                 ["image of ancient ruins in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 50, 20],
                 ["image of castle on hilltop in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 50, 10],
                 ["image of amphiteater in sks style, 8k, high quality, old paper","colored, deformed, blurry, grain, artifacts, low quality", 1, 40, 9],
                 ["image of church in lake in sks style, 8k, high quality, old paper, black and white","colored, deformed, blurry, grain, artifacts, low quality", 1, 40, 18],
                 ["image of village on hilltop with citadel in sks style, 8k, high quality, old paper, black and white","colored, deformed, blurry, grain, artifacts, low quality", 1, 40, 18]],
                [prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images)

demo.launch(debug=True)