Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import numpy as np
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from matplotlib.animation import FuncAnimation, PillowWriter
|
| 5 |
import scipy.io.wavfile as wavfile
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
# Constants for sound generation
|
| 9 |
SAMPLE_RATE = 48000
|
|
@@ -173,20 +172,19 @@ def create_animation(matrix):
|
|
| 173 |
|
| 174 |
ani = FuncAnimation(fig, update, frames=None, interval=1000, blit=True)
|
| 175 |
|
| 176 |
-
# Save the animation to a GIF
|
| 177 |
-
|
| 178 |
-
ani.save(
|
| 179 |
plt.close(fig)
|
| 180 |
-
gif_buffer.seek(0)
|
| 181 |
|
| 182 |
-
return
|
| 183 |
|
| 184 |
def run_simulation(matrix_input):
|
| 185 |
"""
|
| 186 |
Run the full simulation based on user-input matrix
|
| 187 |
|
| 188 |
:param matrix_input: 2D list of integers representing the matrix
|
| 189 |
-
:return: tuple of (audio_path,
|
| 190 |
"""
|
| 191 |
# Convert input to numpy array
|
| 192 |
matrix = np.array(matrix_input, dtype=int)
|
|
@@ -209,9 +207,9 @@ def run_simulation(matrix_input):
|
|
| 209 |
wavfile.write(audio_path, SAMPLE_RATE, final_audio)
|
| 210 |
|
| 211 |
# Create animation
|
| 212 |
-
|
| 213 |
|
| 214 |
-
return audio_path,
|
| 215 |
|
| 216 |
# Gradio Interface
|
| 217 |
def create_gradio_interface():
|
|
@@ -238,7 +236,7 @@ def create_gradio_interface():
|
|
| 238 |
],
|
| 239 |
outputs=[
|
| 240 |
gr.Audio(type="filepath", label="Generated Sound"),
|
| 241 |
-
gr.Image(type="
|
| 242 |
],
|
| 243 |
title="Number Spread Simulator",
|
| 244 |
description="Edit the matrix and see how numbers spread, generating a unique sound and animation!"
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from matplotlib.animation import FuncAnimation, PillowWriter
|
| 5 |
import scipy.io.wavfile as wavfile
|
|
|
|
| 6 |
|
| 7 |
# Constants for sound generation
|
| 8 |
SAMPLE_RATE = 48000
|
|
|
|
| 172 |
|
| 173 |
ani = FuncAnimation(fig, update, frames=None, interval=1000, blit=True)
|
| 174 |
|
| 175 |
+
# Save the animation to a GIF file
|
| 176 |
+
gif_path = "matrix_animation.gif"
|
| 177 |
+
ani.save(gif_path, format='gif', writer=PillowWriter(fps=1))
|
| 178 |
plt.close(fig)
|
|
|
|
| 179 |
|
| 180 |
+
return gif_path
|
| 181 |
|
| 182 |
def run_simulation(matrix_input):
|
| 183 |
"""
|
| 184 |
Run the full simulation based on user-input matrix
|
| 185 |
|
| 186 |
:param matrix_input: 2D list of integers representing the matrix
|
| 187 |
+
:return: tuple of (audio_path, gif_path)
|
| 188 |
"""
|
| 189 |
# Convert input to numpy array
|
| 190 |
matrix = np.array(matrix_input, dtype=int)
|
|
|
|
| 207 |
wavfile.write(audio_path, SAMPLE_RATE, final_audio)
|
| 208 |
|
| 209 |
# Create animation
|
| 210 |
+
gif_path = create_animation(matrix)
|
| 211 |
|
| 212 |
+
return audio_path, gif_path
|
| 213 |
|
| 214 |
# Gradio Interface
|
| 215 |
def create_gradio_interface():
|
|
|
|
| 236 |
],
|
| 237 |
outputs=[
|
| 238 |
gr.Audio(type="filepath", label="Generated Sound"),
|
| 239 |
+
gr.Image(type="filepath", label="Matrix Animation")
|
| 240 |
],
|
| 241 |
title="Number Spread Simulator",
|
| 242 |
description="Edit the matrix and see how numbers spread, generating a unique sound and animation!"
|