Badr AlKhamissi commited on
Commit
aaf94ae
1 Parent(s): 470b2c3

resolving gif issue

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -8,6 +8,7 @@ import random
8
  import numpy.random as npr
9
  import sys
10
  import imageio
 
11
 
12
  # sys.path.append('./code')
13
 
@@ -222,7 +223,7 @@ def run_main_app(semantic_concept, word, prompt_suffix, font_name, num_steps, se
222
  img = img[:, :, 3:4] * img[:, :, :3] + torch.ones(img.shape[0], img.shape[1], 3, device=device) * (
223
  1 - img[:, :, 3:4])
224
  img = img[:, :, :3]
225
- gif_frames += [img.detach().cpu().numpy()]
226
 
227
 
228
  filename = os.path.join(cfg.experiment_dir, "video-svg", f"iter{step:04d}.svg")
@@ -259,7 +260,7 @@ def run_main_app(semantic_concept, word, prompt_suffix, font_name, num_steps, se
259
  combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir, device)
260
 
261
  filename = os.path.join(cfg.experiment_dir, "final.gif")
262
- imageio.mimsave(filename, gif_frames)
263
 
264
  yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=filename,visible=True)
265
 
@@ -357,7 +358,7 @@ with gr.Blocks() as demo:
357
  with gr.Column():
358
  result0 = gr.Image(type="filepath", label="Initial Word").style(height=250)
359
  result1 = gr.Image(type="filepath", label="Optimization Process").style(height=300)
360
- result2 = gr.Video(type="filepath", label="Final Result",visible=False).style(height=300)
361
 
362
 
363
  with gr.Row():
 
8
  import numpy.random as npr
9
  import sys
10
  import imageio
11
+ import numpy as np
12
 
13
  # sys.path.append('./code')
14
 
 
223
  img = img[:, :, 3:4] * img[:, :, :3] + torch.ones(img.shape[0], img.shape[1], 3, device=device) * (
224
  1 - img[:, :, 3:4])
225
  img = img[:, :, :3]
226
+ gif_frames += [img.detach().cpu().numpy()*255]
227
 
228
 
229
  filename = os.path.join(cfg.experiment_dir, "video-svg", f"iter{step:04d}.svg")
 
260
  combine_word(cfg.word, cfg.optimized_letter, cfg.font, cfg.experiment_dir, device)
261
 
262
  filename = os.path.join(cfg.experiment_dir, "final.gif")
263
+ imageio.mimsave(filename, np.array(gif_frames).astype(np.uint8))
264
 
265
  yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=filename,visible=True)
266
 
 
358
  with gr.Column():
359
  result0 = gr.Image(type="filepath", label="Initial Word").style(height=250)
360
  result1 = gr.Image(type="filepath", label="Optimization Process").style(height=300)
361
+ result2 = gr.Image(type="filepath", label="Final Result",visible=False).style(height=300)
362
 
363
 
364
  with gr.Row():