kadirnar commited on
Commit
6dceec4
β€’
1 Parent(s): 7bd3018

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +4 -4
  2. app.py +25 -0
  3. requirements.txt +2 -0
  4. utils_app.py +122 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Traditional Furniture Demo
3
- emoji: πŸ‘
4
- colorFrom: gray
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 3.20.1
8
  app_file: app.py
 
1
  ---
2
+ title: Lowpoly World Demo
3
+ emoji: πŸ‘€
4
+ colorFrom: indigo
5
+ colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.20.1
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from utils_app import keras_stable_diffusion_app
2
+ import gradio as gr
3
+
4
+ app = gr.Blocks()
5
+ with app:
6
+ gr.HTML(
7
+ """
8
+ <h1 style='text-align: center'>
9
+ Keras Diffusion WebUI
10
+ </h1>
11
+ """
12
+ )
13
+ gr.Markdown(
14
+ """
15
+ <h4 style='text-align: center'>
16
+ Follow me for more!
17
+ <a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a>
18
+ </h4>
19
+ """
20
+ )
21
+ with gr.Row():
22
+ with gr.Column():
23
+ keras_diffusion_app = keras_stable_diffusion_app()
24
+
25
+ app.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ keras_cv
2
+ tensorflow
utils_app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_keras
2
+ from keras_cv import models
3
+ from tensorflow import keras
4
+ import tensorflow as tf
5
+ import gradio as gr
6
+
7
+ keras_model_list = [
8
+ "kadirnar/dreambooth_diffusion_model_v5",
9
+
10
+ ]
11
+
12
+ stable_prompt_list = [
13
+ "a photo of sks traditional furniture",
14
+ ]
15
+
16
+ stable_negative_prompt_list = [
17
+ "bad, ugly",
18
+ "deformed"
19
+ ]
20
+
21
+ def keras_stable_diffusion(
22
+ model_path:str,
23
+ prompt:str,
24
+ negative_prompt:str,
25
+ guidance_scale:int,
26
+ num_inference_step:int,
27
+ height:int,
28
+ width:int,
29
+ ):
30
+
31
+ keras.mixed_precision.set_global_policy("mixed_float16")
32
+
33
+ sd_dreambooth_model = models.StableDiffusion(
34
+ img_width=height,
35
+ img_height=width
36
+ )
37
+
38
+ db_diffusion_model = from_pretrained_keras(model_path)
39
+ sd_dreambooth_model._diffusion_model = db_diffusion_model
40
+
41
+ generated_images = sd_dreambooth_model.text_to_image(
42
+ prompt=prompt,
43
+ negative_prompt=negative_prompt,
44
+ num_steps=num_inference_step,
45
+ unconditional_guidance_scale=guidance_scale
46
+ )
47
+
48
+ return generated_images
49
+
50
+ def keras_stable_diffusion_app():
51
+ with gr.Blocks():
52
+ with gr.Row():
53
+ with gr.Column():
54
+ keras_text2image_model_path = gr.Dropdown(
55
+ choices=keras_model_list,
56
+ value=keras_model_list[0],
57
+ label='Text-Image Model Id'
58
+ )
59
+
60
+ keras_text2image_prompt = gr.Textbox(
61
+ lines=1,
62
+ value=stable_prompt_list[0],
63
+ label='Prompt'
64
+ )
65
+
66
+ keras_text2image_negative_prompt = gr.Textbox(
67
+ lines=1,
68
+ value=stable_negative_prompt_list[0],
69
+ label='Negative Prompt'
70
+ )
71
+
72
+ with gr.Accordion("Advanced Options", open=False):
73
+ keras_text2image_guidance_scale = gr.Slider(
74
+ minimum=0.1,
75
+ maximum=15,
76
+ step=0.1,
77
+ value=7.5,
78
+ label='Guidance Scale'
79
+ )
80
+
81
+ keras_text2image_num_inference_step = gr.Slider(
82
+ minimum=1,
83
+ maximum=100,
84
+ step=1,
85
+ value=50,
86
+ label='Num Inference Step'
87
+ )
88
+
89
+ keras_text2image_height = gr.Slider(
90
+ minimum=128,
91
+ maximum=1280,
92
+ step=32,
93
+ value=512,
94
+ label='Image Height'
95
+ )
96
+
97
+ keras_text2image_width = gr.Slider(
98
+ minimum=128,
99
+ maximum=1280,
100
+ step=32,
101
+ value=512,
102
+ label='Image Height'
103
+ )
104
+
105
+ keras_text2image_predict = gr.Button(value='Generator')
106
+
107
+ with gr.Column():
108
+ output_image = gr.Gallery(label='Output')
109
+
110
+ keras_text2image_predict.click(
111
+ fn=keras_stable_diffusion,
112
+ inputs=[
113
+ keras_text2image_model_path,
114
+ keras_text2image_prompt,
115
+ keras_text2image_negative_prompt,
116
+ keras_text2image_guidance_scale,
117
+ keras_text2image_num_inference_step,
118
+ keras_text2image_height,
119
+ keras_text2image_width
120
+ ],
121
+ outputs=output_image
122
+ )