Spaces:
Runtime error
Runtime error
fix bugs.
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import os
|
|
7 |
import torch
|
8 |
import time
|
9 |
from PIL import Image
|
10 |
-
|
11 |
def process_multi_wrapper(rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
12 |
shared_prompt,
|
13 |
width_0, width_1, width_2, width_3,
|
@@ -19,10 +19,9 @@ def process_multi_wrapper(rendered_txt_0, rendered_txt_1, rendered_txt_2, render
|
|
19 |
shared_num_samples, shared_image_resolution,
|
20 |
shared_ddim_steps, shared_guess_mode,
|
21 |
shared_strength, shared_scale, shared_seed,
|
22 |
-
shared_eta, shared_a_prompt, shared_n_prompt):
|
23 |
-
|
24 |
-
|
25 |
-
return "Please get the glyph image first by clicking the 'Render Glyph Image' button", None
|
26 |
|
27 |
rendered_txt_values = [rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3]
|
28 |
width_values = [width_0, width_1, width_2, width_3]
|
@@ -31,7 +30,7 @@ def process_multi_wrapper(rendered_txt_0, rendered_txt_1, rendered_txt_2, render
|
|
31 |
top_left_y_values = [top_left_y_0, top_left_y_1, top_left_y_2, top_left_y_3]
|
32 |
yaw_values = [yaw_0, yaw_1, yaw_2, yaw_3]
|
33 |
num_rows_values = [num_rows_0, num_rows_1, num_rows_2, num_rows_3]
|
34 |
-
|
35 |
return "The image generation process finished!", render_tool.process_multi(rendered_txt_values, shared_prompt,
|
36 |
width_values, ratio_values,
|
37 |
top_left_x_values, top_left_y_values,
|
@@ -40,7 +39,7 @@ def process_multi_wrapper(rendered_txt_0, rendered_txt_1, rendered_txt_2, render
|
|
40 |
shared_ddim_steps, shared_guess_mode,
|
41 |
shared_strength, shared_scale, shared_seed,
|
42 |
shared_eta, shared_a_prompt, shared_n_prompt
|
43 |
-
)
|
44 |
|
45 |
def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
46 |
shared_prompt,
|
@@ -53,8 +52,7 @@ def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, ren
|
|
53 |
shared_num_samples, shared_image_resolution,
|
54 |
shared_ddim_steps, shared_guess_mode,
|
55 |
shared_strength, shared_scale, shared_seed,
|
56 |
-
shared_eta, shared_a_prompt, shared_n_prompt):
|
57 |
-
global ALLOW_RUN_GENERATION
|
58 |
rendered_txt_values = [rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3]
|
59 |
width_values = [width_0, width_1, width_2, width_3]
|
60 |
ratio_values = [ratio_0, ratio_1, ratio_2, ratio_3]
|
@@ -62,7 +60,7 @@ def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, ren
|
|
62 |
top_left_y_values = [top_left_y_0, top_left_y_1, top_left_y_2, top_left_y_3]
|
63 |
yaw_values = [yaw_0, yaw_1, yaw_2, yaw_3]
|
64 |
num_rows_values = [num_rows_0, num_rows_1, num_rows_2, num_rows_3]
|
65 |
-
|
66 |
|
67 |
return "The glyph image is generated!", render_tool.process_multi(rendered_txt_values, shared_prompt,
|
68 |
width_values, ratio_values,
|
@@ -72,7 +70,7 @@ def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, ren
|
|
72 |
shared_ddim_steps, shared_guess_mode,
|
73 |
shared_strength, shared_scale, shared_seed,
|
74 |
shared_eta, shared_a_prompt, shared_n_prompt,
|
75 |
-
only_show_rendered_image=True)
|
76 |
|
77 |
def load_ckpt(model_ckpt = "LAION-Glyph-10M-Epoch-5"):
|
78 |
global render_tool, model
|
@@ -103,7 +101,8 @@ def load_ckpt(model_ckpt = "LAION-Glyph-10M-Epoch-5"):
|
|
103 |
torch.cuda.empty_cache()
|
104 |
time.sleep(2)
|
105 |
print("empty the cuda cache")
|
106 |
-
|
|
|
107 |
|
108 |
|
109 |
cfg = OmegaConf.load("config.yaml")
|
@@ -156,7 +155,10 @@ with block:
|
|
156 |
shared_prompt = gr.Textbox(label="Shared Prompt")
|
157 |
with gr.Row():
|
158 |
show_render_button = gr.Button(value="Render Glyph Image")
|
159 |
-
run_button = gr.Button(value="Run Generation")
|
|
|
|
|
|
|
160 |
with gr.Accordion("Model Options", open=False):
|
161 |
with gr.Row():
|
162 |
# model_ckpt = gr.inputs.Dropdown(["LAION-Glyph-10M", "Textcaps5K-10"], label="Checkpoint", default = "LAION-Glyph-10M")
|
@@ -176,7 +178,7 @@ with block:
|
|
176 |
shared_ddim_steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=20, step=1)
|
177 |
shared_eta = gr.Number(label="eta (DDIM)", value=0.0, visible=False)
|
178 |
with gr.Row():
|
179 |
-
shared_a_prompt = gr.Textbox(label="Added Prompt", value='best quality, extremely detailed')
|
180 |
shared_n_prompt = gr.Textbox(label="Negative Prompt",
|
181 |
value='longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality')
|
182 |
|
@@ -198,8 +200,8 @@ with block:
|
|
198 |
shared_num_samples, shared_image_resolution,
|
199 |
shared_ddim_steps, shared_guess_mode,
|
200 |
shared_strength, shared_scale, shared_seed,
|
201 |
-
shared_eta, shared_a_prompt, shared_n_prompt],
|
202 |
-
outputs=[message, result_gallery])
|
203 |
|
204 |
show_render_button.click(fn=process_multi_wrapper_only_show_rendered,
|
205 |
inputs=[rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
@@ -214,11 +216,11 @@ with block:
|
|
214 |
shared_ddim_steps, shared_guess_mode,
|
215 |
shared_strength, shared_scale, shared_seed,
|
216 |
shared_eta, shared_a_prompt, shared_n_prompt],
|
217 |
-
outputs=[message, result_gallery])
|
218 |
|
219 |
model_ckpt.change(load_ckpt,
|
220 |
inputs = [model_ckpt],
|
221 |
-
outputs = [message, result_gallery]
|
222 |
)
|
223 |
|
224 |
block.launch()
|
|
|
7 |
import torch
|
8 |
import time
|
9 |
from PIL import Image
|
10 |
+
|
11 |
def process_multi_wrapper(rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
12 |
shared_prompt,
|
13 |
width_0, width_1, width_2, width_3,
|
|
|
19 |
shared_num_samples, shared_image_resolution,
|
20 |
shared_ddim_steps, shared_guess_mode,
|
21 |
shared_strength, shared_scale, shared_seed,
|
22 |
+
shared_eta, shared_a_prompt, shared_n_prompt, allow_run_generation = True):
|
23 |
+
if not allow_run_generation:
|
24 |
+
return "Please get the glyph image first by clicking the 'Render Glyph Image' button", None, allow_run_generation
|
|
|
25 |
|
26 |
rendered_txt_values = [rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3]
|
27 |
width_values = [width_0, width_1, width_2, width_3]
|
|
|
30 |
top_left_y_values = [top_left_y_0, top_left_y_1, top_left_y_2, top_left_y_3]
|
31 |
yaw_values = [yaw_0, yaw_1, yaw_2, yaw_3]
|
32 |
num_rows_values = [num_rows_0, num_rows_1, num_rows_2, num_rows_3]
|
33 |
+
allow_run_generation = False
|
34 |
return "The image generation process finished!", render_tool.process_multi(rendered_txt_values, shared_prompt,
|
35 |
width_values, ratio_values,
|
36 |
top_left_x_values, top_left_y_values,
|
|
|
39 |
shared_ddim_steps, shared_guess_mode,
|
40 |
shared_strength, shared_scale, shared_seed,
|
41 |
shared_eta, shared_a_prompt, shared_n_prompt
|
42 |
+
), allow_run_generation
|
43 |
|
44 |
def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
45 |
shared_prompt,
|
|
|
52 |
shared_num_samples, shared_image_resolution,
|
53 |
shared_ddim_steps, shared_guess_mode,
|
54 |
shared_strength, shared_scale, shared_seed,
|
55 |
+
shared_eta, shared_a_prompt, shared_n_prompt):
|
|
|
56 |
rendered_txt_values = [rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3]
|
57 |
width_values = [width_0, width_1, width_2, width_3]
|
58 |
ratio_values = [ratio_0, ratio_1, ratio_2, ratio_3]
|
|
|
60 |
top_left_y_values = [top_left_y_0, top_left_y_1, top_left_y_2, top_left_y_3]
|
61 |
yaw_values = [yaw_0, yaw_1, yaw_2, yaw_3]
|
62 |
num_rows_values = [num_rows_0, num_rows_1, num_rows_2, num_rows_3]
|
63 |
+
allow_run_generation = True
|
64 |
|
65 |
return "The glyph image is generated!", render_tool.process_multi(rendered_txt_values, shared_prompt,
|
66 |
width_values, ratio_values,
|
|
|
70 |
shared_ddim_steps, shared_guess_mode,
|
71 |
shared_strength, shared_scale, shared_seed,
|
72 |
shared_eta, shared_a_prompt, shared_n_prompt,
|
73 |
+
only_show_rendered_image=True), allow_run_generation
|
74 |
|
75 |
def load_ckpt(model_ckpt = "LAION-Glyph-10M-Epoch-5"):
|
76 |
global render_tool, model
|
|
|
101 |
torch.cuda.empty_cache()
|
102 |
time.sleep(2)
|
103 |
print("empty the cuda cache")
|
104 |
+
allow_run_generation = False
|
105 |
+
return output_str, None, allow_run_generation
|
106 |
|
107 |
|
108 |
cfg = OmegaConf.load("config.yaml")
|
|
|
155 |
shared_prompt = gr.Textbox(label="Shared Prompt")
|
156 |
with gr.Row():
|
157 |
show_render_button = gr.Button(value="Render Glyph Image")
|
158 |
+
run_button = gr.Button(value="Run Generation")
|
159 |
+
allow_run_generation = gr.Checkbox(label='allow_run_generation',
|
160 |
+
value=False, visible=False)
|
161 |
+
|
162 |
with gr.Accordion("Model Options", open=False):
|
163 |
with gr.Row():
|
164 |
# model_ckpt = gr.inputs.Dropdown(["LAION-Glyph-10M", "Textcaps5K-10"], label="Checkpoint", default = "LAION-Glyph-10M")
|
|
|
178 |
shared_ddim_steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=20, step=1)
|
179 |
shared_eta = gr.Number(label="eta (DDIM)", value=0.0, visible=False)
|
180 |
with gr.Row():
|
181 |
+
shared_a_prompt = gr.Textbox(label="Added Prompt", value='4K, dslr, best quality, extremely detailed')
|
182 |
shared_n_prompt = gr.Textbox(label="Negative Prompt",
|
183 |
value='longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality')
|
184 |
|
|
|
200 |
shared_num_samples, shared_image_resolution,
|
201 |
shared_ddim_steps, shared_guess_mode,
|
202 |
shared_strength, shared_scale, shared_seed,
|
203 |
+
shared_eta, shared_a_prompt, shared_n_prompt, allow_run_generation],
|
204 |
+
outputs=[message, result_gallery, allow_run_generation])
|
205 |
|
206 |
show_render_button.click(fn=process_multi_wrapper_only_show_rendered,
|
207 |
inputs=[rendered_txt_0, rendered_txt_1, rendered_txt_2, rendered_txt_3,
|
|
|
216 |
shared_ddim_steps, shared_guess_mode,
|
217 |
shared_strength, shared_scale, shared_seed,
|
218 |
shared_eta, shared_a_prompt, shared_n_prompt],
|
219 |
+
outputs=[message, result_gallery, allow_run_generation])
|
220 |
|
221 |
model_ckpt.change(load_ckpt,
|
222 |
inputs = [model_ckpt],
|
223 |
+
outputs = [message, result_gallery, allow_run_generation]
|
224 |
)
|
225 |
|
226 |
block.launch()
|