Badr AlKhamissi commited on
Commit
ffa9150
1 Parent(s): 7c3835f

changed final gif to video

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -62,7 +62,7 @@ DESCRIPTION += '\n<p>Note: it takes about 5 minutes for 500 iterations to genera
62
 
63
  if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
64
  DESCRIPTION = DESCRIPTION.replace("</p>", " ")
65
- DESCRIPTION += f'or duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
66
  else:
67
  DESCRIPTION = DESCRIPTION.replace("either", "")
68
 
@@ -174,7 +174,7 @@ def run_main_app(semantic_concept, word, prompt_suffix, font_name, num_steps, se
174
  preprocess(cfg.font, cfg.word, cfg.optimized_letter, cfg.level_of_cc)
175
  filename_init = os.path.join("code/data/init/", f"{cfg.font}_{cfg.word}_scaled.svg").replace(" ", "_")
176
  if not example:
177
- yield gr.update(value=filename_init,visible=True),gr.update(visible=True, label=f'iters: 0 / {cfg.num_iter}'),gr.update(visible=False)
178
 
179
  sds_loss = SDSLoss(cfg, device, model)
180
 
@@ -263,8 +263,11 @@ def run_main_app(semantic_concept, word, prompt_suffix, font_name, num_steps, se
263
 
264
  # combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir, device)
265
 
266
- filename = os.path.join(cfg.experiment_dir, "final.gif")
267
- imageio.mimsave(filename, np.array(gif_frames).astype(np.uint8))
 
 
 
268
 
269
  yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=filename,visible=True)
270
 
@@ -362,14 +365,14 @@ with gr.Blocks() as demo:
362
  with gr.Column():
363
  result0 = gr.Image(type="filepath", label="Initial Word").style(height=250)
364
  result1 = gr.Image(type="filepath", label="Optimization Process").style(height=300)
365
- result2 = gr.Image(type="filepath", label="Final Result",visible=False).style(height=300)
366
 
367
 
368
  with gr.Row():
369
  # examples
370
  examples = [
371
  ["قطة", "Cat", 250, 42],
372
- ["جمل جميل", "Horse", 250, 42],
373
  ["كلب", "Dog", 250, 42],
374
  ["أخطبوط", "Octopus", 250, 42],
375
  ]
 
62
 
63
  if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
64
  DESCRIPTION = DESCRIPTION.replace("</p>", " ")
65
+ DESCRIPTION += f'or <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate the Space"/></a> and upgrade to GPU in settings.</p>'
66
  else:
67
  DESCRIPTION = DESCRIPTION.replace("either", "")
68
 
 
174
  preprocess(cfg.font, cfg.word, cfg.optimized_letter, cfg.level_of_cc)
175
  filename_init = os.path.join("code/data/init/", f"{cfg.font}_{cfg.word}_scaled.svg").replace(" ", "_")
176
  if not example:
177
+ yield gr.update(value=filename_init,visible=True),gr.update(visible=True, label='Initializing'),gr.update(visible=False)
178
 
179
  sds_loss = SDSLoss(cfg, device, model)
180
 
 
263
 
264
  # combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir, device)
265
 
266
+ filename = os.path.join(cfg.experiment_dir, "final.mp4")
267
+ writer = imageio.get_writer(filename, fps=20)
268
+ for frame in gif_frames: writer.append_data(frame)
269
+ writer.close()
270
+ # imageio.mimsave(filename, np.array(gif_frames).astype(np.uint8))
271
 
272
  yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=filename,visible=True)
273
 
 
365
  with gr.Column():
366
  result0 = gr.Image(type="filepath", label="Initial Word").style(height=250)
367
  result1 = gr.Image(type="filepath", label="Optimization Process").style(height=300)
368
+ result2 = gr.Video(type="filepath", label="Final Result",visible=False).style(height=300)
369
 
370
 
371
  with gr.Row():
372
  # examples
373
  examples = [
374
  ["قطة", "Cat", 250, 42],
375
+ ["جمل جميل", "Camel", 250, 42],
376
  ["كلب", "Dog", 250, 42],
377
  ["أخطبوط", "Octopus", 250, 42],
378
  ]