Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|