vumichien commited on
Commit
f183568
1 Parent(s): 4d8b54b

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_akitainu")
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 photo of hks## toy"),
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=12),
36
+ ], [
37
+ gr.Gallery(show_label=False),
38
+ ],
39
+ title="Keras Dreambooth - Aikta dog Demo 🐶",
40
+ description = "This model has been fine tuned to learn the concept of Akita dog-a famous and very cute dog of Japane. To use this demo, you should have {akt## dog} in the input",
41
+ examples = [["akt## dog as an anime character in overwatch", "((ugly)), blurry, ((bad anatomy)), duplicate", 4, 100, 12],
42
+ ["cute and adorable cartoon fluffy akt## dog with cap, fantasy, dreamlike, city scenario, surrealism, super cute, trending on artstation", "((ugly)), blurry, ((bad anatomy)), duplicate", 4, 100, 12]],
43
+ cache_examples=True
44
+ ).queue().launch(debug=True, share=True)