yyk19 commited on
Commit
e06ab5a
1 Parent(s): efe1cad

update codes to support the scenario when no glyph instructions are provided.

Browse files
Files changed (2) hide show
  1. app.py +8 -4
  2. scripts/rendertext_tool.py +9 -3
app.py CHANGED
@@ -1,4 +1,3 @@
1
- from cldm.ddim_hacked import DDIMSampler
2
  import math
3
  from omegaconf import OmegaConf
4
  from scripts.rendertext_tool import Render_Text, load_model_from_config, load_model_ckpt
@@ -63,8 +62,8 @@ def process_multi_wrapper_only_show_rendered(rendered_txt_0, rendered_txt_1, ren
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
  allow_run_generation = True
66
-
67
- return "The glyph image is generated!", render_tool.process_multi(rendered_txt_values, shared_prompt,
68
  width_values, ratio_values,
69
  top_left_x_values, top_left_y_values,
70
  yaw_values, num_rows_values,
@@ -72,7 +71,12 @@ 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), allow_run_generation
 
 
 
 
 
76
 
77
  def load_ckpt(model_ckpt = "LAION-Glyph-10M-Epoch-5"):
78
  global render_tool, model
 
 
1
  import math
2
  from omegaconf import OmegaConf
3
  from scripts.rendertext_tool import Render_Text, load_model_from_config, load_model_ckpt
 
62
  yaw_values = [yaw_0, yaw_1, yaw_2, yaw_3]
63
  num_rows_values = [num_rows_0, num_rows_1, num_rows_2, num_rows_3]
64
  allow_run_generation = True
65
+
66
+ glyph_image = render_tool.process_multi(rendered_txt_values, shared_prompt,
67
  width_values, ratio_values,
68
  top_left_x_values, top_left_y_values,
69
  yaw_values, num_rows_values,
 
71
  shared_ddim_steps, shared_guess_mode,
72
  shared_strength, shared_scale, shared_seed,
73
  shared_eta, shared_a_prompt, shared_n_prompt,
74
+ only_show_rendered_image=True)
75
+
76
+ if glyph_image[0] is None:
77
+ return "Warning: no glyph image would be rendered because the glyph insructions are not provided!", glyph_image, allow_run_generation
78
+ else:
79
+ return "The glyph image is successfully rendered!", glyph_image, allow_run_generation
80
 
81
  def load_ckpt(model_ckpt = "LAION-Glyph-10M-Epoch-5"):
82
  global render_tool, model
scripts/rendertext_tool.py CHANGED
@@ -83,7 +83,8 @@ class Render_Text:
83
  self.transform = transform
84
  self.ddim_sampler = DDIMSampler(model)
85
  self.save_memory = save_memory
86
-
 
87
  def process_multi(self,
88
  rendered_txt_values, shared_prompt,
89
  width_values, ratio_values,
@@ -102,8 +103,12 @@ class Render_Text:
102
  self.precision_scope("cuda"), \
103
  self.model.ema_scope("Sampling on Benchmark Prompts"):
104
  print("rendered txt:", str(rendered_txt_values), "[t]")
105
- if rendered_txt_values == "":
 
 
106
  control = None
 
 
107
  else:
108
  def format_bboxes(width_values, ratio_values, top_left_x_values, top_left_y_values, yaw_values):
109
  bboxes = []
@@ -193,7 +198,8 @@ class Render_Text:
193
  x_samples = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
194
 
195
  results = [x_samples[i] for i in range(shared_num_samples)]
196
- if rendered_txt_values != "":
 
197
  return [whiteboard_img] + results
198
  else:
199
  return results
 
83
  self.transform = transform
84
  self.ddim_sampler = DDIMSampler(model)
85
  self.save_memory = save_memory
86
+
87
+ # process multiple groups of rendered text for building demo
88
  def process_multi(self,
89
  rendered_txt_values, shared_prompt,
90
  width_values, ratio_values,
 
103
  self.precision_scope("cuda"), \
104
  self.model.ema_scope("Sampling on Benchmark Prompts"):
105
  print("rendered txt:", str(rendered_txt_values), "[t]")
106
+ render_none = len([1 for rendered_txt in rendered_txt_values if rendered_txt != ""]) == 0
107
+ if render_none:
108
+ # if rendered_txt_values == "":
109
  control = None
110
+ if only_show_rendered_image:
111
+ return [None]
112
  else:
113
  def format_bboxes(width_values, ratio_values, top_left_x_values, top_left_y_values, yaw_values):
114
  bboxes = []
 
198
  x_samples = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
199
 
200
  results = [x_samples[i] for i in range(shared_num_samples)]
201
+ # if rendered_txt_values != "":
202
+ if not render_none:
203
  return [whiteboard_img] + results
204
  else:
205
  return results