Spaces:
Sleeping
Sleeping
gpt test
Browse files
app.py
CHANGED
@@ -1,7 +1,32 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import librosa
|
5 |
+
import librosa.display
|
6 |
|
7 |
+
def plot_stft(audio_file):
|
8 |
+
# Load audio file
|
9 |
+
y, sr = librosa.load(audio_file)
|
10 |
+
|
11 |
+
# Compute the Short-Time Fourier Transform (STFT)
|
12 |
+
D = librosa.stft(y)
|
13 |
+
S_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)
|
14 |
+
|
15 |
+
# Plot the STFT
|
16 |
+
plt.figure(figsize=(10, 6))
|
17 |
+
librosa.display.specshow(S_db, sr=sr, x_axis='time', y_axis='log')
|
18 |
+
plt.colorbar(format='%+2.0f dB')
|
19 |
+
plt.title('STFT (Short-Time Fourier Transform)')
|
20 |
+
|
21 |
+
# Save the plot as an image
|
22 |
+
plt.savefig('stft_plot.png')
|
23 |
+
plt.close()
|
24 |
+
|
25 |
+
return 'stft_plot.png'
|
26 |
+
|
27 |
+
# Gradio interface
|
28 |
+
demo = gr.Interface(fn=plot_stft,
|
29 |
+
inputs=gr.Audio(type="filepath"),
|
30 |
+
outputs="image")
|
31 |
|
|
|
32 |
demo.launch()
|