Spaces:
Runtime error
Runtime error
Pbars
Browse files
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
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|