staghado commited on
Commit
038be2c
1 Parent(s): 1b9b1dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -92,12 +92,16 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
92
  yield from animate(frame, coefs, np.linspace(0, 1, num=frames))
93
 
94
  # Generate final animation as GIF
95
- anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, np.linspace(0, 1, num=frames)))
96
- gif_buf = io.BytesIO()
97
- anim.save(gif_buf, 'output.gif', fps=15)
98
- gif_buf.seek(0)
99
- final_gif = Image.open(gif_buf)
100
- final_gif = np.array(final_gif.convert('RGB'))
 
 
 
 
101
 
102
  # Yield the final GIF in place of the last frame
103
  yield (image, final_gif)
 
92
  yield from animate(frame, coefs, np.linspace(0, 1, num=frames))
93
 
94
  # Generate final animation as GIF
95
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.gif') as temp_file:
96
+ anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, np.linspace(0, 1, num=frames)))
97
+ anim.save(temp_file.name, fps=15)
98
+
99
+ # Read the final GIF
100
+ with open(temp_file.name, 'rb') as gif_file:
101
+ final_gif = np.array(Image.open(io.BytesIO(gif_file.read())))
102
+
103
+ # Remove the temporary file
104
+ os.remove(temp_file.name)
105
 
106
  # Yield the final GIF in place of the last frame
107
  yield (image, final_gif)