SemanticTypography commited on
Commit
e40a416
·
verified ·
1 Parent(s): 5c8c871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -44
app.py CHANGED
@@ -152,10 +152,7 @@ def run_main_app(semantic_concept, word, letter, font_name, num_steps, example=0
152
  preprocess(cfg.font, cfg.word, cfg.optimized_letter, cfg.level_of_cc)
153
  filename_init = os.path.join("code/data/init/", f"{cfg.font}_{cfg.word}_scaled.svg").replace(" ", "_")
154
  if not example:
155
- with open(filename_init, "r") as f0:
156
- svg_content_init = f0.read()
157
- # yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(visible=False)
158
- yield gr.update(value=f'<div>{svg_content_init}</div>',label="Initial Word",visible=True),gr.update(visible=False),gr.update(visible=False)
159
 
160
  sds_loss = SDSLoss(cfg, device, model)
161
 
@@ -210,10 +207,7 @@ def run_main_app(semantic_concept, word, letter, font_name, num_steps, example=0
210
  check_and_create_dir(filename)
211
  save_svg.save_svg(filename, w, h, shapes, shape_groups)
212
  if not example:
213
- # yield gr.update(visible=True),gr.update(value=filename, label=f'iters: {step} / {num_iter}', visible=True),gr.update(visible=False)
214
- with open(filename, "r") as f:
215
- svg_content = f.read()
216
- yield gr.update(visible=True), gr.update(value=f'<div>{svg_content}</div>',label=f'iters: {step} / {num_iter}',visible=True),gr.update(visible=False)
217
 
218
  x = img.unsqueeze(0).permute(0, 3, 1, 2) # HWC -> NCHW
219
  x = x.repeat(cfg.batch_size, 1, 1, 1)
@@ -243,15 +237,7 @@ def run_main_app(semantic_concept, word, letter, font_name, num_steps, example=0
243
  combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir)
244
 
245
  image = os.path.join(cfg.experiment_dir,f"{cfg.font}_{cfg.word}_{cfg.optimized_letter}.svg")
246
- # yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=image,visible=True)
247
-
248
- with open(filename_init, "r") as f0:
249
- svg_content_init = f0.read()
250
-
251
- with open(image, "r") as f1:
252
- svg_content_final = f1.read()
253
-
254
- yield gr.update(value=f'<div style="width: 333px; height: 333px;">{svg_content_init}</div>',label="Initial Word",visible=True),gr.update(visible=False),gr.update(value=f"<div>{svg_content_final}</div>",label="Final Result",visible=True)
255
 
256
 
257
  with gr.Blocks() as demo:
@@ -293,7 +279,7 @@ with gr.Blocks() as demo:
293
  font_name = gr.Text(value=None,visible=False,label="Font Name")
294
  gallery = gr.Gallery(value=[(os.path.join("images","KaushanScript-Regular.png"),"KaushanScript-Regular"), (os.path.join("images","IndieFlower-Regular.png"),"IndieFlower-Regular"),(os.path.join("images","Quicksand.png"),"Quicksand"),
295
  (os.path.join("images","Saira-Regular.png"),"Saira-Regular"), (os.path.join("images","LuckiestGuy-Regular.png"),"LuckiestGuy-Regular"),(os.path.join("images","DeliusUnicase-Regular.png"),"DeliusUnicase-Regular"),
296
- (os.path.join("images","Noteworthy-Bold.png"),"Noteworthy-Bold"), (os.path.join("images","HobeauxRococeaux-Sherman.png"),"HobeauxRococeaux-Sherman")],label="Font Name",columns=4, height=400, object_fit="contain")
297
 
298
  def on_select(evt: gr.SelectData):
299
  return evt.value
@@ -303,9 +289,9 @@ with gr.Blocks() as demo:
303
  run = gr.Button('Generate')
304
 
305
  with gr.Column():
306
- result0 = gr.HTML() #gr.Image(type="filepath", label="Initial Word",height=333)
307
- result1 = gr.HTML() #gr.Image(type="filepath", label="Optimization Process",height=100)
308
- result2 = gr.HTML() #gr.Image(type="filepath", label="Final Result",visible=False,height=333)
309
 
310
 
311
  with gr.Row():
@@ -316,30 +302,31 @@ with gr.Blocks() as demo:
316
  "BUNNY",
317
  "Y",
318
  "KaushanScript-Regular",
319
- 1# 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  ],
321
- # [
322
- # "LION",
323
- # "LION",
324
- # "O",
325
- # "Quicksand",
326
- # 500
327
- # ],
328
- # [
329
- # "FROG",
330
- # "FROG",
331
- # "G",
332
- # "IndieFlower-Regular",
333
- # 500
334
- # ],
335
- # [
336
- # "CAT",
337
- # "CAT",
338
- # "C",
339
- # "LuckiestGuy-Regular",
340
- # 500
341
- # ],
342
  ]
 
343
  gr.Examples(examples=examples,
344
  inputs=[
345
  semantic_concept,
@@ -372,7 +359,7 @@ with gr.Blocks() as demo:
372
  result2
373
  ]
374
 
375
- run.click(fn=run_main_app, inputs=inputs, outputs=outputs, concurrency_limit=2)
376
 
377
 
378
  demo.launch(share=False)
 
152
  preprocess(cfg.font, cfg.word, cfg.optimized_letter, cfg.level_of_cc)
153
  filename_init = os.path.join("code/data/init/", f"{cfg.font}_{cfg.word}_scaled.svg").replace(" ", "_")
154
  if not example:
155
+ yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(visible=False)
 
 
 
156
 
157
  sds_loss = SDSLoss(cfg, device, model)
158
 
 
207
  check_and_create_dir(filename)
208
  save_svg.save_svg(filename, w, h, shapes, shape_groups)
209
  if not example:
210
+ yield gr.update(visible=True),gr.update(value=filename, label=f'iters: {step} / {num_iter}', visible=True),gr.update(visible=False)
 
 
 
211
 
212
  x = img.unsqueeze(0).permute(0, 3, 1, 2) # HWC -> NCHW
213
  x = x.repeat(cfg.batch_size, 1, 1, 1)
 
237
  combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir)
238
 
239
  image = os.path.join(cfg.experiment_dir,f"{cfg.font}_{cfg.word}_{cfg.optimized_letter}.svg")
240
+ yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=image,visible=True)
 
 
 
 
 
 
 
 
241
 
242
 
243
  with gr.Blocks() as demo:
 
279
  font_name = gr.Text(value=None,visible=False,label="Font Name")
280
  gallery = gr.Gallery(value=[(os.path.join("images","KaushanScript-Regular.png"),"KaushanScript-Regular"), (os.path.join("images","IndieFlower-Regular.png"),"IndieFlower-Regular"),(os.path.join("images","Quicksand.png"),"Quicksand"),
281
  (os.path.join("images","Saira-Regular.png"),"Saira-Regular"), (os.path.join("images","LuckiestGuy-Regular.png"),"LuckiestGuy-Regular"),(os.path.join("images","DeliusUnicase-Regular.png"),"DeliusUnicase-Regular"),
282
+ (os.path.join("images","Noteworthy-Bold.png"),"Noteworthy-Bold"), (os.path.join("images","HobeauxRococeaux-Sherman.png"),"HobeauxRococeaux-Sherman")],label="Font Name").style(grid=4)
283
 
284
  def on_select(evt: gr.SelectData):
285
  return evt.value
 
289
  run = gr.Button('Generate')
290
 
291
  with gr.Column():
292
+ result0 = gr.Image(type="filepath", label="Initial Word").style(height=333)
293
+ result1 = gr.Image(type="filepath", label="Optimization Process").style(height=110)
294
+ result2 = gr.Image(type="filepath", label="Final Result",visible=False).style(height=333)
295
 
296
 
297
  with gr.Row():
 
302
  "BUNNY",
303
  "Y",
304
  "KaushanScript-Regular",
305
+ 500
306
+ ],
307
+ [
308
+ "LION",
309
+ "LION",
310
+ "O",
311
+ "Quicksand",
312
+ 500
313
+ ],
314
+ [
315
+ "FROG",
316
+ "FROG",
317
+ "G",
318
+ "IndieFlower-Regular",
319
+ 500
320
+ ],
321
+ [
322
+ "CAT",
323
+ "CAT",
324
+ "C",
325
+ "LuckiestGuy-Regular",
326
+ 500
327
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  ]
329
+ demo.queue(max_size=10, concurrency_count=2)
330
  gr.Examples(examples=examples,
331
  inputs=[
332
  semantic_concept,
 
359
  result2
360
  ]
361
 
362
+ run.click(fn=run_main_app, inputs=inputs, outputs=outputs, queue=True)
363
 
364
 
365
  demo.launch(share=False)