staghado commited on
Commit
1663e03
·
1 Parent(s): 14400f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -65,7 +65,7 @@ def animate(frame, coefs, time, fig, ax, background, circles, circle_lines, draw
65
  center = (0, 0)
66
  for idx, (r, fr) in enumerate(coefs_static):
67
  c_dynamic = coefs[idx][0] * np.exp(1j * (fr * tau * time[frame]))
68
- x, y = center[0] + r * np.cos(theta), center[1] + r * np.sin(theta)
69
  circle_lines[idx].set_data([center[0], center[0] + np.real(c_dynamic)], [center[1], center[1] + np.imag(c_dynamic)])
70
  circles[idx].set_data(x, y)
71
  center = (center[0] + np.real(c_dynamic), center[1] + np.imag(c_dynamic))
@@ -81,14 +81,13 @@ def animate(frame, coefs, time, fig, ax, background, circles, circle_lines, draw
81
  ax.draw_artist(drawing)
82
 
83
  fig.canvas.blit(ax.bbox)
 
 
 
 
 
84
 
85
- # Capture the frame as an image
86
- fig.canvas.draw()
87
- image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8')
88
- image = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))
89
-
90
- yield Image.fromarray(image)
91
-
92
 
93
  def generate_animation(frames, coefs, img_size, desired_range, theta_points, coefficients):
94
  fig, ax, background, circles, circle_lines, drawing = setup_animation_env(img_size, desired_range, coefficients)
@@ -112,7 +111,7 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
112
  anim.save(temp_file.name, fps=15)
113
 
114
  for frame in range(frames):
115
- yield from animate(frame, coefs, time, fig, ax, background, circles, circle_lines, drawing, draw_x, draw_y, coefs_static, theta), temp_file.name
116
 
117
  def setup_gradio_interface():
118
  interface = gr.Interface(
 
65
  center = (0, 0)
66
  for idx, (r, fr) in enumerate(coefs_static):
67
  c_dynamic = coefs[idx][0] * np.exp(1j * (fr * tau * time[frame]))
68
+ x, y = center[0] + r * np.cos(theta[frame]), center[1] + r * np.sin(theta[frame])
69
  circle_lines[idx].set_data([center[0], center[0] + np.real(c_dynamic)], [center[1], center[1] + np.imag(c_dynamic)])
70
  circles[idx].set_data(x, y)
71
  center = (center[0] + np.real(c_dynamic), center[1] + np.imag(c_dynamic))
 
81
  ax.draw_artist(drawing)
82
 
83
  fig.canvas.blit(ax.bbox)
84
+
85
+ # Convert canvas to PIL Image using buffer_rgba
86
+ #fig.canvas.draw()
87
+ buffer = fig.canvas.buffer_rgba()
88
+ pil_image = Image.frombuffer("RGBA", fig.canvas.get_width_height(), buffer, "raw", "RGBA", 0, 1)
89
 
90
+ return (pil_image, None)
 
 
 
 
 
 
91
 
92
  def generate_animation(frames, coefs, img_size, desired_range, theta_points, coefficients):
93
  fig, ax, background, circles, circle_lines, drawing = setup_animation_env(img_size, desired_range, coefficients)
 
111
  anim.save(temp_file.name, fps=15)
112
 
113
  for frame in range(frames):
114
+ yield (animate(frame, coefs, time, fig, ax, background, circles, circle_lines, drawing, draw_x, draw_y, coefs_static, theta), temp_file.name)
115
 
116
  def setup_gradio_interface():
117
  interface = gr.Interface(