Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -77,22 +77,30 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
|
|
77 |
draw_y.append(center[1])
|
78 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
79 |
|
80 |
-
|
|
|
81 |
buf = io.BytesIO()
|
82 |
plt.savefig(buf, format='png', bbox_inches='tight')
|
83 |
buf.seek(0)
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
-
# Generate and yield images
|
87 |
for frame in range(frames):
|
88 |
yield from animate(frame, coefs, np.linspace(0, 1, num=frames))
|
89 |
|
90 |
-
# Generate final animation
|
91 |
anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, np.linspace(0, 1, num=frames)))
|
92 |
-
|
93 |
-
anim.save(
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
|
97 |
# Gradio interface setup
|
98 |
interface = gr.Interface(
|
@@ -107,7 +115,7 @@ interface = gr.Interface(
|
|
107 |
gr.Number(value=1000, label="Number of Points for Integration", precision=0),
|
108 |
gr.Slider(minimum=50, maximum=500, value=80, label="Theta Points for Animation")
|
109 |
],
|
110 |
-
outputs=["image", "
|
111 |
title="Fourier Transform Drawing",
|
112 |
description="Upload an image and generate a Fourier Transform drawing animation.",
|
113 |
)
|
|
|
77 |
draw_y.append(center[1])
|
78 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
79 |
|
80 |
+
|
81 |
+
# Capture the current plot as an image
|
82 |
buf = io.BytesIO()
|
83 |
plt.savefig(buf, format='png', bbox_inches='tight')
|
84 |
buf.seek(0)
|
85 |
+
image = np.array(Image.open(buf))
|
86 |
+
|
87 |
+
# Yield the current image and a placeholder for the final animation
|
88 |
+
yield (image, None)
|
89 |
|
90 |
+
# Generate and yield images for each frame
|
91 |
for frame in range(frames):
|
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, format='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)
|
104 |
|
105 |
# Gradio interface setup
|
106 |
interface = gr.Interface(
|
|
|
115 |
gr.Number(value=1000, label="Number of Points for Integration", precision=0),
|
116 |
gr.Slider(minimum=50, maximum=500, value=80, label="Theta Points for Animation")
|
117 |
],
|
118 |
+
outputs=["image", "image"],
|
119 |
title="Fourier Transform Drawing",
|
120 |
description="Upload an image and generate a Fourier Transform drawing animation.",
|
121 |
)
|