JadenFK commited on
Commit
88c9af4
1 Parent(s): ffae5f8
Files changed (2) hide show
  1. app.py +21 -3
  2. test.py +39 -32
app.py CHANGED
@@ -16,6 +16,9 @@ class Demo:
16
 
17
  def __init__(self) -> None:
18
 
 
 
 
19
  with gr.Blocks() as demo:
20
  self.layout()
21
  demo.queue(concurrency_count=10).launch()
@@ -56,9 +59,10 @@ class Demo:
56
  label="Learning Rate",
57
  info='Learning rate used to train'
58
  )
 
 
59
  self.train_button = gr.Button(
60
  value="Train",
61
-
62
  )
63
 
64
 
@@ -107,11 +111,16 @@ class Demo:
107
  self.iterations_input,
108
  self.lr_input
109
  ],
110
- outputs=[self.train_button, self.infr_button]
111
  )
112
 
113
  def train(self, prompt, train_method, neg_guidance, iterations, lr, pbar = gr.Progress(track_tqdm=True)):
114
 
 
 
 
 
 
115
  model_orig, model_edited = train_esd(prompt,
116
  train_method,
117
  3,
@@ -132,7 +141,7 @@ class Demo:
132
 
133
  self.init_inference(model_edited_sd, model_orig_sd, unet_config)
134
 
135
- return [gr.update(interactive=True), gr.update(interactive=True)]
136
 
137
  def init_inference(self, model_edited_sd, model_orig_sd, unet_config):
138
 
@@ -144,9 +153,16 @@ class Demo:
144
  self.diffuser.unet = UNet2DConditionModel(**unet_config)
145
  self.diffuser.to('cuda')
146
 
 
 
147
 
148
  def inference(self, prompt):
149
 
 
 
 
 
 
150
  self.diffuser.unet.load_state_dict(self.model_orig_sd)
151
 
152
  images = self.diffuser(
@@ -167,6 +183,8 @@ class Demo:
167
 
168
  edited_image = images[0][0]
169
 
 
 
170
  return edited_image, orig_image
171
 
172
 
 
16
 
17
  def __init__(self) -> None:
18
 
19
+ self.training = False
20
+ self.generating = False
21
+
22
  with gr.Blocks() as demo:
23
  self.layout()
24
  demo.queue(concurrency_count=10).launch()
 
59
  label="Learning Rate",
60
  info='Learning rate used to train'
61
  )
62
+ self.progress_bar = gr.Text(interactive=False, label="Training Progress")
63
+
64
  self.train_button = gr.Button(
65
  value="Train",
 
66
  )
67
 
68
 
 
111
  self.iterations_input,
112
  self.lr_input
113
  ],
114
+ outputs=[self.train_button, self.infr_button, self.progress_bar]
115
  )
116
 
117
  def train(self, prompt, train_method, neg_guidance, iterations, lr, pbar = gr.Progress(track_tqdm=True)):
118
 
119
+ if self.training:
120
+ return [None, None, None]
121
+ else:
122
+ self.training = True
123
+
124
  model_orig, model_edited = train_esd(prompt,
125
  train_method,
126
  3,
 
141
 
142
  self.init_inference(model_edited_sd, model_orig_sd, unet_config)
143
 
144
+ return [gr.update(interactive=True), gr.update(interactive=True), None]
145
 
146
  def init_inference(self, model_edited_sd, model_orig_sd, unet_config):
147
 
 
153
  self.diffuser.unet = UNet2DConditionModel(**unet_config)
154
  self.diffuser.to('cuda')
155
 
156
+ self.training = False
157
+
158
 
159
  def inference(self, prompt):
160
 
161
+ if self.generating:
162
+ return [None, None]
163
+ else:
164
+ self.generating = True
165
+
166
  self.diffuser.unet.load_state_dict(self.model_orig_sd)
167
 
168
  images = self.diffuser(
 
183
 
184
  edited_image = images[0][0]
185
 
186
+ self.generating = False
187
+
188
  return edited_image, orig_image
189
 
190
 
test.py CHANGED
@@ -1,32 +1,39 @@
1
- import sys
2
- sys.path.insert(0,'stable_diffusion')
3
- from train_esd import train_esd
4
- import torch
5
- ckpt_path = "stable_diffusion/models/ldm/sd-v1-4-full-ema.ckpt"
6
- config_path = "stable_diffusion/configs/stable-diffusion/v1-inference.yaml"
7
- diffusers_config_path = "stable_diffusion/config.json"
8
-
9
- orig, newm = train_esd("England",
10
- 'xattn',
11
- 3,
12
- 1,
13
- 2,
14
- .003,
15
- config_path,
16
- ckpt_path,
17
- diffusers_config_path,
18
- ['cuda', 'cuda'],
19
- None
20
- )
21
-
22
-
23
- from convertModels import convert_ldm_unet_checkpoint, create_unet_diffusers_config
24
- from diffusers import UNet2DConditionModel, AutoencoderKL, LMSDiscreteScheduler
25
- from omegaconf import OmegaConf
26
- from transformers import CLIPTextModel, CLIPTokenizer
27
- original_config = OmegaConf.load(config_path)
28
- original_config["model"]["params"]["unet_config"]["params"]["in_channels"] = 4
29
- unet_config = create_unet_diffusers_config(original_config, image_size=512)
30
- converted_unet_checkpoint = convert_ldm_unet_checkpoint(newm.state_dict(), unet_config)
31
- unet = UNet2DConditionModel(**unet_config)
32
- unet.load_state_dict(converted_unet_checkpoint)
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ import gradio as gr
5
+ import time
6
+
7
+ def slowly_reverse(word, progress=gr.Progress()):
8
+ progress(0, desc="Starting")
9
+ time.sleep(1)
10
+ progress(0.05)
11
+ new_string = ""
12
+ for letter in progress.tqdm(word, desc="Reversing"):
13
+ time.sleep(0.25)
14
+ new_string = letter + new_string
15
+ return new_string, None
16
+
17
+ with gr.Blocks() as demo:
18
+
19
+ with gr.Row(elem_id=123) as row:
20
+
21
+ t1 = gr.Text()
22
+ t2 = gr.Text()
23
+
24
+ b = gr.Button("Test")
25
+
26
+
27
+ with gr.Row():
28
+
29
+ sl = gr.Text(interactive=False)
30
+
31
+
32
+ b.click(slowly_reverse,
33
+ inputs = [t1],
34
+ outputs= [t2, sl],
35
+ show_progress=True
36
+ )
37
+
38
+
39
+ demo.queue(concurrency_count=10).launch()