Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -29,19 +29,14 @@ def generate_frequency_visualization(audio_path):
|
|
29 |
os.makedirs('frames', exist_ok=True)
|
30 |
|
31 |
# Generate and save each frame
|
32 |
-
for i
|
33 |
plt.figure(figsize=(10, 6))
|
34 |
-
librosa.display.specshow(
|
35 |
plt.axis('off')
|
36 |
plt.savefig(f'frames/frame_{i:04d}.png', bbox_inches='tight', pad_inches=0)
|
37 |
plt.close()
|
38 |
|
39 |
-
print(f"Generated {
|
40 |
-
return 'frames'
|
41 |
-
except ZeroDivisionError as e:
|
42 |
-
print(f"ZeroDivisionError: {e}")
|
43 |
-
# Fallback: Generate a default visualization
|
44 |
-
generate_default_visualization()
|
45 |
return 'frames'
|
46 |
except Exception as e:
|
47 |
print(f"Error generating frequency visualization: {e}")
|
@@ -113,7 +108,3 @@ if __name__ == "__main__":
|
|
113 |
# - numpy
|
114 |
# - matplotlib
|
115 |
# - moviepy
|
116 |
-
# - gradio
|
117 |
-
#
|
118 |
-
# You can install these dependencies using pip:
|
119 |
-
# pip install librosa numpy matplotlib moviepy gradio
|
|
|
29 |
os.makedirs('frames', exist_ok=True)
|
30 |
|
31 |
# Generate and save each frame
|
32 |
+
for i in range(D.shape[1]): # Iterate over columns of D (time frames)
|
33 |
plt.figure(figsize=(10, 6))
|
34 |
+
librosa.display.specshow(D[:, i].reshape(-1, 1), sr=sr, x_axis='time', y_axis='log', hop_length=hop_length, cmap='viridis')
|
35 |
plt.axis('off')
|
36 |
plt.savefig(f'frames/frame_{i:04d}.png', bbox_inches='tight', pad_inches=0)
|
37 |
plt.close()
|
38 |
|
39 |
+
print(f"Generated {D.shape[1]} frames for visualization.")
|
|
|
|
|
|
|
|
|
|
|
40 |
return 'frames'
|
41 |
except Exception as e:
|
42 |
print(f"Error generating frequency visualization: {e}")
|
|
|
108 |
# - numpy
|
109 |
# - matplotlib
|
110 |
# - moviepy
|
|
|
|
|
|
|
|