justus-tobias commited on
Commit
b312806
1 Parent(s): 642c276

fixed issue with gradio df

Browse files
Files changed (3) hide show
  1. app.py +30 -20
  2. requirements.txt +98 -80
  3. utils.py +1 -90
app.py CHANGED
@@ -9,6 +9,7 @@ import itertools
9
  import tempfile
10
  import librosa
11
  import random
 
12
  import os
13
 
14
  from utils import getaudiodata, getBeats, plotBeattimes, find_s1s2
@@ -216,9 +217,11 @@ def getBeatsv2(audio:gr.Audio):
216
 
217
 
218
 
219
- return fig, featuredf, (sr, audiodata)
220
 
221
- def updateBeatsv2(beattimes_table:gr.Dataframe, audio:gr.Audio, uploadeddf:gr.File=None)-> go.Figure:
 
 
222
 
223
  sr, audiodata = getaudiodata(audio)
224
 
@@ -231,9 +234,13 @@ def updateBeatsv2(beattimes_table:gr.Dataframe, audio:gr.Audio, uploadeddf:gr.Fi
231
 
232
  fig = plotBeattimes(s1_times, audiodata, sr, s2_times)
233
 
234
- return fig, beattimes_table
 
 
 
 
235
 
236
- def download_df (df: pd.DataFrame):
237
 
238
  temp_dir = tempfile.gettempdir()
239
  temp_path = os.path.join(temp_dir, "feature_data.csv")
@@ -262,26 +269,29 @@ with gr.Blocks() as app:
262
 
263
  beats_wave_plot = gr.Plot()
264
 
265
- beattimes_df = gr.Dataframe(
266
- value = pd.DataFrame({"Beattimes":[], "S1 to S2":[], "S2 to S1":[], "Label (S1=0/S2=1)":[]}),
267
- label="Beattimes")
268
 
269
  with gr.Row():
270
 
271
- csv_download = gr.DownloadButton()
272
-
273
- updateBeatsbtn = gr.Button("update Beats")
274
-
275
- uploadDF = gr.File(
276
- file_count="single",
277
- file_types=[".csv"],
278
- label="upload a csv",
279
- height=25
280
- )
281
 
282
- csv_download.click(download_df, inputs=[beattimes_df], outputs=[csv_download])
283
- getBeatsbtn.click(getBeatsv2, inputs=audiofile, outputs=[beats_wave_plot, beattimes_df, cleanedaudio])
284
- updateBeatsbtn.click(updateBeatsv2, inputs=[beattimes_df, audiofile, uploadDF], outputs=[beats_wave_plot, beattimes_df])
 
 
 
 
 
 
 
 
 
 
 
 
285
 
286
  gr.Examples(
287
  examples=example_files,
 
9
  import tempfile
10
  import librosa
11
  import random
12
+ import mdpd
13
  import os
14
 
15
  from utils import getaudiodata, getBeats, plotBeattimes, find_s1s2
 
217
 
218
 
219
 
220
+ return fig, featuredf.to_markdown(), (sr, audiodata)
221
 
222
+ def updateBeatsv2(beattimes_table:gr.Markdown, audio:gr.Audio, uploadeddf:gr.File=None)-> go.Figure:
223
+
224
+ df = mdpd.from_md(df)
225
 
226
  sr, audiodata = getaudiodata(audio)
227
 
 
234
 
235
  fig = plotBeattimes(s1_times, audiodata, sr, s2_times)
236
 
237
+ return fig, beattimes_table.to_markdown()
238
+
239
+ def download_df (df: str):
240
+
241
+ df = mdpd.from_md(df)
242
 
243
+ print(df)
244
 
245
  temp_dir = tempfile.gettempdir()
246
  temp_path = os.path.join(temp_dir, "feature_data.csv")
 
269
 
270
  beats_wave_plot = gr.Plot()
271
 
272
+
 
 
273
 
274
  with gr.Row():
275
 
276
+ with gr.Column():
277
+
278
+ beattimes_table = gr.Markdown()
 
 
 
 
 
 
 
279
 
280
+ with gr.Column():
281
+
282
+ csv_download = gr.DownloadButton()
283
+ updateBeatsbtn = gr.Button("update Beats")
284
+
285
+ uploadDF = gr.File(
286
+ file_count="single",
287
+ file_types=[".csv"],
288
+ label="upload a csv",
289
+ height=25
290
+ )
291
+
292
+ csv_download.click(download_df, inputs=[beattimes_table], outputs=[csv_download])
293
+ getBeatsbtn.click(getBeatsv2, inputs=audiofile, outputs=[beats_wave_plot, beattimes_table, cleanedaudio])
294
+ updateBeatsbtn.click(updateBeatsv2, inputs=[beattimes_table, audiofile, uploadDF], outputs=[beats_wave_plot, beattimes_table])
295
 
296
  gr.Examples(
297
  examples=example_files,
requirements.txt CHANGED
@@ -1,80 +1,98 @@
1
- aiofiles==23.2.1
2
- annotated-types==0.7.0
3
- anyio==4.4.0
4
- audioread==3.0.1
5
- certifi==2024.8.30
6
- cffi==1.17.1
7
- charset-normalizer==3.3.2
8
- click==8.1.7
9
- contourpy==1.3.0
10
- cycler==0.12.1
11
- decorator==5.1.1
12
- fastapi==0.114.2
13
- ffmpy==0.4.0
14
- filelock==3.16.0
15
- fonttools==4.53.1
16
- fsspec==2024.9.0
17
- gradio==4.44.0
18
- gradio_client==1.3.0
19
- h11==0.14.0
20
- httpcore==1.0.5
21
- httpx==0.27.2
22
- huggingface-hub==0.24.7
23
- idna==3.10
24
- importlib_resources==6.4.5
25
- Jinja2==3.1.4
26
- joblib==1.4.2
27
- kiwisolver==1.4.7
28
- lazy_loader==0.4
29
- librosa==0.10.2.post1
30
- llvmlite==0.43.0
31
- markdown-it-py==3.0.0
32
- MarkupSafe==2.1.5
33
- matplotlib==3.9.2
34
- mdurl==0.1.2
35
- msgpack==1.1.0
36
- numba==0.60.0
37
- numpy==2.0.2
38
- orjson==3.10.7
39
- packaging==24.1
40
- pandas==2.2.2
41
- pillow==10.4.0
42
- pip==24.2
43
- platformdirs==4.3.3
44
- plotly==5.24.1
45
- pooch==1.8.2
46
- pycparser==2.22
47
- pydantic==2.9.1
48
- pydantic_core==2.23.3
49
- pydub==0.25.1
50
- Pygments==2.18.0
51
- pyparsing==3.1.4
52
- python-dateutil==2.9.0.post0
53
- python-multipart==0.0.9
54
- pytz==2024.2
55
- PyWavelets==1.7.0
56
- PyYAML==6.0.2
57
- requests==2.32.3
58
- rich==13.8.1
59
- ruff==0.6.5
60
- scikit-learn==1.5.2
61
- scipy==1.14.1
62
- semantic-version==2.10.0
63
- setuptools==72.1.0
64
- shellingham==1.5.4
65
- six==1.16.0
66
- sniffio==1.3.1
67
- soundfile==0.12.1
68
- soxr==0.5.0.post1
69
- starlette==0.38.5
70
- tenacity==9.0.0
71
- threadpoolctl==3.5.0
72
- tomlkit==0.12.0
73
- tqdm==4.66.5
74
- typer==0.12.5
75
- typing_extensions==4.12.2
76
- tzdata==2024.1
77
- urllib3==2.2.3
78
- uvicorn==0.30.6
79
- websockets==12.0
80
- wheel==0.44.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file may be used to create an environment using:
2
+ # $ conda create --name <env> --file <this file>
3
+ # platform: osx-arm64
4
+ aiofiles=23.2.1=pypi_0
5
+ annotated-types=0.7.0=pypi_0
6
+ anyio=4.4.0=pypi_0
7
+ audioread=3.0.1=pypi_0
8
+ bzip2=1.0.8=h80987f9_6
9
+ ca-certificates=2024.7.2=hca03da5_0
10
+ certifi=2024.8.30=pypi_0
11
+ cffi=1.17.1=pypi_0
12
+ charset-normalizer=3.3.2=pypi_0
13
+ click=8.1.7=pypi_0
14
+ contourpy=1.3.0=pypi_0
15
+ cycler=0.12.1=pypi_0
16
+ decorator=5.1.1=pypi_0
17
+ expat=2.6.3=h313beb8_0
18
+ fastapi=0.114.2=pypi_0
19
+ ffmpy=0.4.0=pypi_0
20
+ filelock=3.16.0=pypi_0
21
+ fonttools=4.53.1=pypi_0
22
+ fsspec=2024.9.0=pypi_0
23
+ gradio=4.44.0=pypi_0
24
+ gradio-client=1.3.0=pypi_0
25
+ h11=0.14.0=pypi_0
26
+ httpcore=1.0.5=pypi_0
27
+ httpx=0.27.2=pypi_0
28
+ huggingface-hub=0.24.7=pypi_0
29
+ idna=3.10=pypi_0
30
+ importlib-resources=6.4.5=pypi_0
31
+ jinja2=3.1.4=pypi_0
32
+ joblib=1.4.2=pypi_0
33
+ kiwisolver=1.4.7=pypi_0
34
+ lazy-loader=0.4=pypi_0
35
+ libcxx=14.0.6=h848a8c0_0
36
+ libffi=3.4.4=hca03da5_1
37
+ librosa=0.10.2.post1=pypi_0
38
+ llvmlite=0.43.0=pypi_0
39
+ markdown-it-py=3.0.0=pypi_0
40
+ markupsafe=2.1.5=pypi_0
41
+ matplotlib=3.9.2=pypi_0
42
+ mdpd=0.2.1=pypi_0
43
+ mdurl=0.1.2=pypi_0
44
+ msgpack=1.1.0=pypi_0
45
+ ncurses=6.4=h313beb8_0
46
+ numba=0.60.0=pypi_0
47
+ numpy=2.0.2=pypi_0
48
+ openssl=3.0.15=h80987f9_0
49
+ orjson=3.10.7=pypi_0
50
+ packaging=24.1=pypi_0
51
+ pandas=2.2.2=pypi_0
52
+ pillow=10.4.0=pypi_0
53
+ pip=24.2=py312hca03da5_0
54
+ platformdirs=4.3.3=pypi_0
55
+ plotly=5.24.1=pypi_0
56
+ pooch=1.8.2=pypi_0
57
+ pycparser=2.22=pypi_0
58
+ pydantic=2.9.1=pypi_0
59
+ pydantic-core=2.23.3=pypi_0
60
+ pydub=0.25.1=pypi_0
61
+ pygments=2.18.0=pypi_0
62
+ pyparsing=3.1.4=pypi_0
63
+ python=3.12.3=h99e199e_1
64
+ python-dateutil=2.9.0.post0=pypi_0
65
+ python-multipart=0.0.9=pypi_0
66
+ pytz=2024.2=pypi_0
67
+ pywavelets=1.7.0=pypi_0
68
+ pyyaml=6.0.2=pypi_0
69
+ readline=8.2=h1a28f6b_0
70
+ requests=2.32.3=pypi_0
71
+ rich=13.8.1=pypi_0
72
+ ruff=0.6.5=pypi_0
73
+ scikit-learn=1.5.2=pypi_0
74
+ scipy=1.14.1=pypi_0
75
+ semantic-version=2.10.0=pypi_0
76
+ setuptools=72.1.0=py312hca03da5_0
77
+ shellingham=1.5.4=pypi_0
78
+ six=1.16.0=pypi_0
79
+ sniffio=1.3.1=pypi_0
80
+ soundfile=0.12.1=pypi_0
81
+ soxr=0.5.0.post1=pypi_0
82
+ sqlite=3.45.3=h80987f9_0
83
+ starlette=0.38.5=pypi_0
84
+ tabulate=0.9.0=pypi_0
85
+ tenacity=9.0.0=pypi_0
86
+ threadpoolctl=3.5.0=pypi_0
87
+ tk=8.6.14=h6ba3021_0
88
+ tomlkit=0.12.0=pypi_0
89
+ tqdm=4.66.5=pypi_0
90
+ typer=0.12.5=pypi_0
91
+ typing-extensions=4.12.2=pypi_0
92
+ tzdata=2024.1=pypi_0
93
+ urllib3=2.2.3=pypi_0
94
+ uvicorn=0.30.6=pypi_0
95
+ websockets=12.0=pypi_0
96
+ wheel=0.44.0=py312hca03da5_0
97
+ xz=5.4.6=h80987f9_1
98
+ zlib=1.2.13=h18a0788_1
utils.py CHANGED
@@ -2,12 +2,9 @@ import librosa
2
  import numpy as np
3
  import plotly.graph_objects as go
4
  from scipy.signal import savgol_filter, find_peaks
5
- from scipy.signal import butter, filtfilt, medfilt, find_peaks, hilbert
6
- from scipy.ndimage import gaussian_filter1d
7
  from sklearn.cluster import KMeans
8
  from sklearn.preprocessing import StandardScaler
9
- from io import StringIO
10
- import soundfile as sf
11
  import pywt
12
  import pandas as pd
13
 
@@ -323,92 +320,6 @@ def getBeats(audiodata: np.ndarray, sr: int, method='envelope') -> tuple[float,
323
 
324
  return tempo, peak_times, cleaned_audio
325
 
326
- # def plotBeattimes(beattimes: np.ndarray, audiodata: np.ndarray, sr: int) -> go.Figure:
327
- # """
328
- # Plot audio waveform with beat markers.
329
-
330
- # Parameters:
331
- # -----------
332
- # beattimes : np.ndarray
333
- # Array of beat times in seconds
334
- # audiodata : np.ndarray
335
- # Audio time series data
336
- # sr : int
337
- # Sampling rate
338
-
339
- # Returns:
340
- # --------
341
- # go.Figure
342
- # Plotly figure with waveform and beat markers
343
- # """
344
- # # Calculate correct time array for the full audio
345
- # time = np.arange(len(audiodata)) / sr
346
-
347
- # # Convert beat times to sample indices
348
- # beat_indices = np.round(beattimes * sr).astype(int)
349
-
350
- # # Ensure indices are within bounds
351
- # beat_indices = beat_indices[beat_indices < len(audiodata)]
352
-
353
- # # Get actual amplitudes at beat positions
354
- # beat_amplitudes = audiodata[beat_indices]
355
-
356
- # # Create the figure
357
- # fig = go.Figure()
358
-
359
- # # Add waveform
360
- # fig.add_trace(
361
- # go.Scatter(
362
- # x=time,
363
- # y=audiodata,
364
- # mode='lines',
365
- # name='Waveform',
366
- # line=dict(color='blue', width=1)
367
- # )
368
- # )
369
-
370
- # # Add beat markers
371
- # fig.add_trace(
372
- # go.Scatter(
373
- # x=beattimes[beat_indices < len(audiodata)], # Use filtered beat times
374
- # y=beat_amplitudes,
375
- # mode='markers',
376
- # name='Beats',
377
- # marker=dict(
378
- # color='red',
379
- # size=8,
380
- # symbol='circle',
381
- # line=dict(color='darkred', width=1)
382
- # )
383
- # )
384
- # )
385
-
386
- # # Update layout
387
- # fig.update_layout(
388
- # title="Audio Waveform with Beat Detection",
389
- # xaxis_title="Time (seconds)",
390
- # yaxis_title="Amplitude",
391
- # showlegend=False,
392
- # hovermode='closest',
393
- # plot_bgcolor='white',
394
- # legend=dict(
395
- # yanchor="top",
396
- # y=0.99,
397
- # xanchor="left",
398
- # x=0.01
399
- # )
400
- # )
401
-
402
- # # Add vertical lines at beat positions (optional)
403
- # for beat_time in beattimes[beat_indices < len(audiodata)]:
404
- # fig.add_vline(
405
- # x=beat_time,
406
- # line=dict(color="rgba(255, 0, 0, 0.2)", width=1),
407
- # layer="below"
408
- # )
409
-
410
- # return fig
411
-
412
  def plotBeattimes(beattimes: np.ndarray,
413
  audiodata: np.ndarray,
414
  sr: int,
 
2
  import numpy as np
3
  import plotly.graph_objects as go
4
  from scipy.signal import savgol_filter, find_peaks
5
+ from scipy.signal import butter, filtfilt, find_peaks
 
6
  from sklearn.cluster import KMeans
7
  from sklearn.preprocessing import StandardScaler
 
 
8
  import pywt
9
  import pandas as pd
10
 
 
320
 
321
  return tempo, peak_times, cleaned_audio
322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  def plotBeattimes(beattimes: np.ndarray,
324
  audiodata: np.ndarray,
325
  sr: int,