staghado commited on
Commit
62895e8
·
1 Parent(s): 46b8412

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -82,15 +82,16 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
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)
94
 
95
  # Generate and yield images for each frame
96
  for frame in range(frames):
@@ -101,9 +102,6 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size, blur_
101
  anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, np.linspace(0, 1, num=frames)))
102
  anim.save(temp_file.name, fps=15)
103
 
104
- # Remove the temporary file
105
- # os.remove(temp_file.name)
106
-
107
  yield (last_image, temp_file.name)
108
 
109
  # Gradio interface setup
 
82
  draw_y.append(center[1])
83
  drawing.set_data(draw_x[:i+1], draw_y[:i+1])
84
 
85
+ # Convert the Matplotlib figure to a PIL Image
86
+ canvas = fig.canvas
87
+ canvas.draw()
88
+ image = Image.frombytes('RGB',
89
+ canvas.get_width_height(),
90
+ canvas.tostring_rgb())
91
  last_image = image
92
 
93
  # Yield the current image and a placeholder for the final animation
94
+ yield (last_image, None)
95
 
96
  # Generate and yield images for each frame
97
  for frame in range(frames):
 
102
  anim = animation.FuncAnimation(fig, animate, frames=frames, interval=5, fargs=(coefs, np.linspace(0, 1, num=frames)))
103
  anim.save(temp_file.name, fps=15)
104
 
 
 
 
105
  yield (last_image, temp_file.name)
106
 
107
  # Gradio interface setup