vumichien commited on
Commit
1966e32
1 Parent(s): b48b50a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ tf.keras.mixed_precision.set_global_policy("mixed_float16")
7
+
8
+ # load keras model
9
+ resolution = 512
10
+ dreambooth_model = models.StableDiffusion(
11
+ img_width=resolution, img_height=resolution, jit_compile=True,
12
+ )
13
+ loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/dreambooth_diffusion_minercraft")
14
+ dreambooth_model._diffusion_model = loaded_diffusion_model
15
+
16
+
17
+ # generate images
18
+ def inference(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale):
19
+ generated_images = dreambooth_model.text_to_image(
20
+ prompt,
21
+ negative_prompt=negative_prompt,
22
+ batch_size=num_imgs_to_gen,
23
+ num_steps=num_steps,
24
+ unconditional_guidance_scale=guidance_scale,
25
+ )
26
+ return generated_images
27
+
28
+
29
+ # pass function, input type for prompt, the output for multiple images
30
+ gr.Interface(
31
+ inference, [
32
+ gr.Textbox(label="Positive Prompt", value="a fishing village under a cherry blossom forest at sunset in mrf style"),
33
+ gr.Textbox(label="Negative Prompt", value="bad anatomy, soft blurry"),
34
+ gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
35
+ gr.Slider(label="Inference Steps",value=20),
36
+ gr.Number(label='Guidance scale', value=7.5),
37
+ ], [
38
+ gr.Gallery(show_label=False),
39
+ ],
40
+ title="Keras Dreambooth - Minecraft Style Demo 🤖",
41
+ description = "This model has been fine tuned to learn the concept of Minecraft",
42
+ ).launch(debug=True, share=True)