vumichien commited on
Commit
671b790
·
1 Parent(s): 5b4d10b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_keras
2
+ from keras_cv import models
3
+ import gradio as gr
4
+ import tensorflow as tf
5
+
6
+ # load keras model
7
+ resolution = 512
8
+ dreambooth_model = models.StableDiffusion(
9
+ img_width=resolution, img_height=resolution, jit_compile=True,
10
+ )
11
+ loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/dreambooth_diffusion_hokusai")
12
+ dreambooth_model._diffusion_model = loaded_diffusion_model
13
+
14
+
15
+ # generate images
16
+ def inference(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale):
17
+ generated_images = 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=guidance_scale,
23
+ )
24
+ return generated_images
25
+
26
+
27
+
28
+ # pass function, input type for prompt, the output for multiple images
29
+ gr.Interface(
30
+ inference, [
31
+ gr.Textbox(label="Positive Prompt", value="a painting image in hks## style"),
32
+ gr.Textbox(label="Negative Prompt", value="bad anatomy, soft blurry"),
33
+ gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
34
+ gr.Slider(label="Inference Steps",value=100),
35
+ gr.Number(label='Guidance scale', value=7.5),
36
+ ], [
37
+ gr.Gallery(show_label=False),
38
+ ],
39
+ title="Keras Dreambooth - Hokusai artist 🏞",
40
+ description = "This model has been fine-tuned to learn the concept of Hokusai artist. To use this demo, you should have {hks## style} in the input",
41
+ examples = [["a painting image of a fishing village under a cherry blossom forest at sunset in hks## style, ultra realistic, 4k, 8k", "bad anatomy, soft blurry", 4, 100, 15],
42
+ ["a beautiful and highly detailed oil painting of a lost valley in the mountains in hks## style, running river, intricate details, 8k, sharp focus, hyper realism", "(bad anatomy), (blurry), grain", 4, 100, 15]],
43
+ cache_examples=True
44
+ ).queue().launch(debug=True, share=True)