Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -66,7 +66,10 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
|
|
66 |
theta = np.linspace(0, tau, theta_points)
|
67 |
coefs_static = [(np.linalg.norm(c), fr) for c, fr in coefs]
|
68 |
|
|
|
|
|
69 |
def animate(i, coefs, time):
|
|
|
70 |
center = (0, 0)
|
71 |
for idx, (r, fr) in enumerate(coefs_static):
|
72 |
c_dynamic = coefs[idx][0] * np.exp(1j * (fr * tau * time[i]))
|
@@ -79,12 +82,12 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
|
|
79 |
draw_y.append(center[1])
|
80 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
81 |
|
82 |
-
|
83 |
# Capture the current plot as an image
|
84 |
buf = io.BytesIO()
|
85 |
plt.savefig(buf, format='png', bbox_inches='tight')
|
86 |
buf.seek(0)
|
87 |
image = np.array(Image.open(buf))
|
|
|
88 |
|
89 |
# Yield the current image and a placeholder for the final animation
|
90 |
yield (image, None)
|
@@ -106,7 +109,7 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
|
|
106 |
os.remove(temp_file.name)
|
107 |
|
108 |
# Yield the final GIF in place of the last frame
|
109 |
-
yield (
|
110 |
|
111 |
# Gradio interface setup
|
112 |
interface = gr.Interface(
|
|
|
66 |
theta = np.linspace(0, tau, theta_points)
|
67 |
coefs_static = [(np.linalg.norm(c), fr) for c, fr in coefs]
|
68 |
|
69 |
+
last_image = None
|
70 |
+
|
71 |
def animate(i, coefs, time):
|
72 |
+
nonlocal last_image
|
73 |
center = (0, 0)
|
74 |
for idx, (r, fr) in enumerate(coefs_static):
|
75 |
c_dynamic = coefs[idx][0] * np.exp(1j * (fr * tau * time[i]))
|
|
|
82 |
draw_y.append(center[1])
|
83 |
drawing.set_data(draw_x[:i+1], draw_y[:i+1])
|
84 |
|
|
|
85 |
# Capture the current plot as an image
|
86 |
buf = io.BytesIO()
|
87 |
plt.savefig(buf, format='png', bbox_inches='tight')
|
88 |
buf.seek(0)
|
89 |
image = np.array(Image.open(buf))
|
90 |
+
last_image = image
|
91 |
|
92 |
# Yield the current image and a placeholder for the final animation
|
93 |
yield (image, None)
|
|
|
109 |
os.remove(temp_file.name)
|
110 |
|
111 |
# Yield the final GIF in place of the last frame
|
112 |
+
yield (last_image, final_gif)
|
113 |
|
114 |
# Gradio interface setup
|
115 |
interface = gr.Interface(
|