Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,46 @@
|
|
1 |
from huggingface_hub import from_pretrained_keras
|
2 |
-
|
3 |
import gradio as gr
|
4 |
-
|
5 |
from tensorflow import keras
|
6 |
|
7 |
keras.mixed_precision.set_global_policy("mixed_float16")
|
8 |
-
|
9 |
-
# prepare model
|
10 |
resolution = 256
|
11 |
-
|
12 |
-
|
13 |
-
)
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
def
|
19 |
-
|
20 |
-
prompt,
|
|
|
|
|
|
|
|
|
21 |
)
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
title = "Dreambooth Piranesi"
|
28 |
-
description = "This is a dreambooth model fine-tuned on the works of art of Giambattista Piranesi."
|
29 |
-
examples=[["image of ancient city, in style sks"]]
|
30 |
-
gr.Interface(infer, inputs=["text"], outputs=[output], title=title, description=description, examples=examples).queue().launch()
|
|
|
1 |
from huggingface_hub import from_pretrained_keras
|
2 |
+
import keras_cv
|
3 |
import gradio as gr
|
|
|
4 |
from tensorflow import keras
|
5 |
|
6 |
keras.mixed_precision.set_global_policy("mixed_float16")
|
7 |
+
# load keras model
|
|
|
8 |
resolution = 256
|
9 |
+
dreambooth_model = keras_cv.models.StableDiffusion(
|
10 |
+
img_width=resolution, img_height=resolution, jit_compile=True,
|
11 |
+
)
|
12 |
+
loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/dreambooth-piranesi")
|
13 |
+
dreambooth_model._diffusion_model = loaded_diffusion_model
|
14 |
|
15 |
+
|
16 |
+
def generate_images(prompt: str, negative_prompt:str, num_imgs_to_gen: int, ugs: int):
|
17 |
+
generated_img = dreambooth_model.text_to_image(
|
18 |
+
prompt,
|
19 |
+
negative_prompt=negative_prompt,
|
20 |
+
batch_size=num_imgs_to_gen,
|
21 |
+
num_steps=num_steps,
|
22 |
+
unconditional_guidance_scale=ugs,
|
23 |
)
|
24 |
+
|
25 |
+
return generated_img
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.HTML("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\"> Dreambooth Piranesi Art </h2>")
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
prompt = gr.Textbox(lines=1, value="image of monuments in sks style", label="Base Prompt")
|
32 |
+
negative_prompt = gr.Textbox(lines=1, value="deformed", label="Negative Prompt")
|
33 |
+
samples = gr.Slider(minimum=1, maximum=5, default=1, step=1, label="Number of Image")
|
34 |
+
num_steps = gr.Slider(label="Inference Steps",value=75)
|
35 |
+
ugs = gr.Slider(minimum=5, maximum=25, default=15, step=1, label="Unconditional Guidance Scale")
|
36 |
+
run = gr.Button(value="Run")
|
37 |
+
with gr.Column():
|
38 |
+
gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
|
39 |
+
|
40 |
+
run.click(generate_images, inputs=[prompt,negative_prompt, samples, num_steps, ugs], outputs=gallery)
|
41 |
|
42 |
+
gr.Examples([["image of monuments in sks style, 8k, high quality, old paper","deformed", 1, 75, 15]],
|
43 |
+
[prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images)
|
44 |
+
# gr.Markdown('\n Demo created by: <a href=\"https://huggingface.co/kadirnar/\">Kadir Nar</a>')
|
45 |
|
46 |
+
demo.launch(debug=True)
|
|
|
|
|
|
|
|